Skip to content
Snippets Groups Projects
Commit 801bf97b authored by Malte Bauch's avatar Malte Bauch
Browse files

Rename device to network element in cli.prompt

parent d1058091
Branches
Tags
1 merge request!410Some basic house keeping
...@@ -46,7 +46,7 @@ import ( ...@@ -46,7 +46,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
// PromptCompleter provides completion for a device. // PromptCompleter provides completion for a Network Element.
type PromptCompleter struct { type PromptCompleter struct {
yangSchemaCompleterMap map[uuid.UUID]*completer.YangSchemaCompleter yangSchemaCompleterMap map[uuid.UUID]*completer.YangSchemaCompleter
currentSuggestions []prompt.Suggest currentSuggestions []prompt.Suggest
...@@ -132,19 +132,19 @@ func filterFlagSlice(input []string) (commandSlice []string, flagSlice []string) ...@@ -132,19 +132,19 @@ func filterFlagSlice(input []string) (commandSlice []string, flagSlice []string)
return commandSlice, flagSlice return commandSlice, flagSlice
} }
func deviceGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []string) []prompt.Suggest { func networkElementGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []string) []prompt.Suggest {
switch inputLen := len(inputSplit); inputLen { switch inputLen := len(inputSplit); inputLen {
case 2: case 2:
return c.updateSuggestionsThroughFunc(d, getDevices) return c.updateSuggestionsThroughFunc(d, getNetworkElements)
case 3: case 3:
id, err := uuid.Parse(inputSplit[inputLen-1]) id, err := uuid.Parse(inputSplit[inputLen-1])
if err != nil { if err != nil {
return c.updateSuggestionsThroughFunc(d, getDevices) return c.updateSuggestionsThroughFunc(d, getNetworkElements)
} }
if c, ok := c.yangSchemaCompleterMap[id]; ok { if c, ok := c.yangSchemaCompleterMap[id]; ok {
return c.Complete(d) return c.Complete(d)
} }
schemaTree, err := getSchemaTreeForDeviceID(id.String()) schemaTree, err := getSchemaTreeForNetworkElementID(id.String())
if err != nil { if err != nil {
return []prompt.Suggest{} return []prompt.Suggest{}
} }
...@@ -158,7 +158,7 @@ func deviceGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []str ...@@ -158,7 +158,7 @@ func deviceGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []str
} }
id, err := uuid.Parse(inputSplit[inputLen-2]) id, err := uuid.Parse(inputSplit[inputLen-2])
if err != nil { if err != nil {
return c.updateSuggestionsThroughFunc(d, getDevices) return c.updateSuggestionsThroughFunc(d, getNetworkElements)
} }
if yc, ok := c.yangSchemaCompleterMap[id]; ok { if yc, ok := c.yangSchemaCompleterMap[id]; ok {
return yc.Complete(d) return yc.Complete(d)
...@@ -216,16 +216,16 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s ...@@ -216,16 +216,16 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
} }
case networkElementRemoveCmd: case networkElementRemoveCmd:
if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") { if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") {
return c.updateSuggestionsThroughFunc(d, getDevices) return c.updateSuggestionsThroughFunc(d, getNetworkElements)
} }
case networkElementGetCmd, networkElementSetCmd: case networkElementGetCmd, networkElementSetCmd:
return deviceGetCompletion(c, d, inputSplit) return networkElementGetCompletion(c, d, inputSplit)
case networkElementShowCmd: case networkElementShowCmd:
devices, err := getDevices() networkElements, err := getNetworkElements()
if err != nil { if err != nil {
return []prompt.Suggest{} return []prompt.Suggest{}
} }
return devices return networkElements
case networkElementCmd, pndCmd, changeCmd: case networkElementCmd, pndCmd, changeCmd:
c.currentSuggestions = nil c.currentSuggestions = nil
return cobraCommandCompletion(cmd, d, inputFlags, []prompt.Suggest{}) return cobraCommandCompletion(cmd, d, inputFlags, []prompt.Suggest{})
...@@ -236,11 +236,11 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s ...@@ -236,11 +236,11 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
return []prompt.Suggest{} return []prompt.Suggest{}
} }
// getDevices is a helper function which requests devices from the controller // getNetworkElements is a helper function which requests Network Elements from the controller
// and gives feedback about the current pulling status with the help of pterm // and gives feedback about the current pulling status with the help of pterm
// the result is converted into a prompt.Suggest slice. // the result is converted into a prompt.Suggest slice.
func getDevices() ([]prompt.Suggest, error) { func getNetworkElements() ([]prompt.Suggest, error) {
spinner, _ := pterm.DefaultSpinner.Start("Fetching devices from controller.") spinner, _ := pterm.DefaultSpinner.Start("Fetching Network Elements from controller.")
resp, err := pndAdapter.GetFlattenedNetworkElements(createContextWithAuthorization()) resp, err := pndAdapter.GetFlattenedNetworkElements(createContextWithAuthorization())
if err != nil { if err != nil {
spinner.Fail(err) spinner.Fail(err)
...@@ -255,11 +255,11 @@ func getDevices() ([]prompt.Suggest, error) { ...@@ -255,11 +255,11 @@ func getDevices() ([]prompt.Suggest, error) {
return completer.SortSuggestionByText(s), nil return completer.SortSuggestionByText(s), nil
} }
// getSchemaTreeForDeviceID is a helper function which requests the SBI's // getSchemaTreeForNetworkElementID is a helper function which requests the SBI's
// schema tree of a specific device. The function gives feedback about the // schema tree of a specific Network Element. The function gives feedback about the
// current pulling status with the help of pterm. // current pulling status with the help of pterm.
func getSchemaTreeForDeviceID(id string) (map[string]*yang.Entry, error) { func getSchemaTreeForNetworkElementID(id string) (map[string]*yang.Entry, error) {
spinner, _ := pterm.DefaultSpinner.Start("Fetching schema tree for Device with ID: ", id) spinner, _ := pterm.DefaultSpinner.Start("Fetching schema tree for Network Element with ID: ", id)
dev, err := pndAdapter.GetNetworkElement(createContextWithAuthorization(), id) dev, err := pndAdapter.GetNetworkElement(createContextWithAuthorization(), id)
if err != nil { if err != nil {
spinner.Fail(err) spinner.Fail(err)
...@@ -347,7 +347,6 @@ var exitCmd = &cobra.Command{ ...@@ -347,7 +347,6 @@ var exitCmd = &cobra.Command{
}, },
} }
// deviceListCmd represents the listDevice command.
var promptCmd = &cobra.Command{ var promptCmd = &cobra.Command{
Use: "prompt", Use: "prompt",
Short: "The prompt command runs the CLI in an interactive shell.", Short: "The prompt command runs the CLI in an interactive shell.",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment