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

WIP

parent 774c7aaa
No related branches found
No related tags found
1 merge request!284Improve usability and better output formatting for gosndc
Pipeline #99403 failed
This commit is part of merge request !284. Comments created here will be created in the context of that merge request.
...@@ -32,7 +32,8 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -32,7 +32,8 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
log "github.com/sirupsen/logrus" "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core"
"github.com/pterm/pterm"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -42,19 +43,24 @@ import ( ...@@ -42,19 +43,24 @@ import (
var pndRemoveCmd = &cobra.Command{ var pndRemoveCmd = &cobra.Command{
Use: "remove", Use: "remove",
Aliases: []string{"rm"}, Aliases: []string{"rm"},
Short: "TODO - not yet implemented", Short: "Removes the PND with the provided ID",
Long: `TODO - not yet implemented`, Long: "Removes the PND with the provided ID",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
spinner, _ := pterm.DefaultSpinner.Start("Fetching changes for type: ", cType.String())
pid, err := uuid.Parse(args[0]) pid, err := uuid.Parse(args[0])
if err != nil { if err != nil {
spinner.Fail(err)
return err return err
} }
resp, err := pndAdapter.RemovePnd(pid) resp, err := pndAdapter.RemovePnd(pid)
if err != nil { if err != nil {
return err return err
} }
log.Infof("Deletion of PND with ID %v: %s", pid, resp.GetStatus().String()) if resp.GetStatus() == core.Status_STATUS_OK {
spinner.Success("PND has been deleted, ID: ", pid)
}
spinner.Fail()
return nil return nil
}, },
} }
......
...@@ -197,7 +197,7 @@ func cobraCommandCompletion(currCmd *cobra.Command, d prompt.Document, inputFlag ...@@ -197,7 +197,7 @@ func cobraCommandCompletion(currCmd *cobra.Command, d prompt.Document, inputFlag
func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []string, inputFlags []string, d prompt.Document) []prompt.Suggest { func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []string, inputFlags []string, d prompt.Document) []prompt.Suggest {
switch cmd { switch cmd {
case pndUseCmd, pndGetCmd: case pndUseCmd, pndGetCmd, pndRemoveCmd:
if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") { if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") {
suggestions := c.updateSuggestionsThroughFunc(d, getPnds) suggestions := c.updateSuggestionsThroughFunc(d, getPnds)
return cobraCommandCompletion(cmd, d, inputFlags, suggestions) return cobraCommandCompletion(cmd, d, inputFlags, suggestions)
...@@ -210,6 +210,10 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s ...@@ -210,6 +210,10 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") { if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") {
return c.updateSuggestionsThroughFunc(d, getConfirmedChanges) return c.updateSuggestionsThroughFunc(d, getConfirmedChanges)
} }
case deviceRemoveCmd:
if len(inputSplit) < 3 || (len(inputSplit) == 3 && d.GetWordBeforeCursor() != "") {
return c.updateSuggestionsThroughFunc(d, getDevices)
}
case deviceGetCmd, deviceSetCmd: case deviceGetCmd, deviceSetCmd:
return deviceGetCompletion(c, d, inputSplit) return deviceGetCompletion(c, d, inputSplit)
case deviceShowCmd: case deviceShowCmd:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment