Skip to content
Snippets Groups Projects

Some basic house keeping

Merged Ghost User requested to merge house-keeping into develop
11 files
+ 78
104
Compare changes
  • Side-by-side
  • Inline
Files
11
+ 17
18
@@ -46,7 +46,7 @@ import (
"github.com/spf13/viper"
)
// PromptCompleter provides completion for a device.
// PromptCompleter provides completion for a Network Element.
type PromptCompleter struct {
yangSchemaCompleterMap map[uuid.UUID]*completer.YangSchemaCompleter
currentSuggestions []prompt.Suggest
@@ -132,19 +132,19 @@ func filterFlagSlice(input []string) (commandSlice []string, flagSlice []string)
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 {
case 2:
return c.updateSuggestionsThroughFunc(d, getDevices)
return c.updateSuggestionsThroughFunc(d, getNetworkElements)
case 3:
id, err := uuid.Parse(inputSplit[inputLen-1])
if err != nil {
return c.updateSuggestionsThroughFunc(d, getDevices)
return c.updateSuggestionsThroughFunc(d, getNetworkElements)
}
if c, ok := c.yangSchemaCompleterMap[id]; ok {
return c.Complete(d)
}
schemaTree, err := getSchemaTreeForDeviceID(id.String())
schemaTree, err := getSchemaTreeForNetworkElementID(id.String())
if err != nil {
return []prompt.Suggest{}
}
@@ -158,7 +158,7 @@ func deviceGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []str
}
id, err := uuid.Parse(inputSplit[inputLen-2])
if err != nil {
return c.updateSuggestionsThroughFunc(d, getDevices)
return c.updateSuggestionsThroughFunc(d, getNetworkElements)
}
if yc, ok := c.yangSchemaCompleterMap[id]; ok {
return yc.Complete(d)
@@ -216,16 +216,16 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
}
case networkElementRemoveCmd:
if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") {
return c.updateSuggestionsThroughFunc(d, getDevices)
return c.updateSuggestionsThroughFunc(d, getNetworkElements)
}
case networkElementGetCmd, networkElementSetCmd:
return deviceGetCompletion(c, d, inputSplit)
return networkElementGetCompletion(c, d, inputSplit)
case networkElementShowCmd:
devices, err := getDevices()
networkElements, err := getNetworkElements()
if err != nil {
return []prompt.Suggest{}
}
return devices
return networkElements
case networkElementCmd, pndCmd, changeCmd:
c.currentSuggestions = nil
return cobraCommandCompletion(cmd, d, inputFlags, []prompt.Suggest{})
@@ -236,11 +236,11 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
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
// the result is converted into a prompt.Suggest slice.
func getDevices() ([]prompt.Suggest, error) {
spinner, _ := pterm.DefaultSpinner.Start("Fetching devices from controller.")
func getNetworkElements() ([]prompt.Suggest, error) {
spinner, _ := pterm.DefaultSpinner.Start("Fetching Network Elements from controller.")
resp, err := pndAdapter.GetFlattenedNetworkElements(createContextWithAuthorization())
if err != nil {
spinner.Fail(err)
@@ -255,11 +255,11 @@ func getDevices() ([]prompt.Suggest, error) {
return completer.SortSuggestionByText(s), nil
}
// getSchemaTreeForDeviceID is a helper function which requests the SBI's
// schema tree of a specific device. The function gives feedback about the
// getSchemaTreeForNetworkElementID is a helper function which requests the SBI's
// schema tree of a specific Network Element. The function gives feedback about the
// current pulling status with the help of pterm.
func getSchemaTreeForDeviceID(id string) (map[string]*yang.Entry, error) {
spinner, _ := pterm.DefaultSpinner.Start("Fetching schema tree for Device with ID: ", id)
func getSchemaTreeForNetworkElementID(id string) (map[string]*yang.Entry, error) {
spinner, _ := pterm.DefaultSpinner.Start("Fetching schema tree for Network Element with ID: ", id)
dev, err := pndAdapter.GetNetworkElement(createContextWithAuthorization(), id)
if err != nil {
spinner.Fail(err)
@@ -347,7 +347,6 @@ var exitCmd = &cobra.Command{
},
}
// deviceListCmd represents the listDevice command.
var promptCmd = &cobra.Command{
Use: "prompt",
Short: "The prompt command runs the CLI in an interactive shell.",
Loading