Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

A pull request for gnmic prompt mode #136

Merged
merged 26 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
310d98f
Added prompt mode and updated gnmic path command
neoul Sep 21, 2020
191f7af
Added generate-schema for tab completion
neoul Sep 21, 2020
25a3269
Added prefix-represented flag to path subcommand
neoul Sep 22, 2020
b9d4315
Updated generateTypeInfo
neoul Sep 22, 2020
b3a2b7f
Added XPATH tab completion
neoul Sep 22, 2020
4e8c93f
Updated command execution
neoul Sep 22, 2020
4c23e0a
Updated path subcommand
neoul Sep 22, 2020
c31cf71
Updated XPATH tab completion
neoul Sep 23, 2020
d946fd4
Merge remote-tracking branch 'mygithub/master'
neoul Sep 23, 2020
2900b1d
Updated showCommandArguments (? key) on the prompt mode
neoul Sep 24, 2020
5e9a7b7
Added gnmic prompt-mode gif
neoul Sep 24, 2020
bd0dd41
Updated README.md
neoul Sep 24, 2020
e4e127a
Updated go.sum and go.mod
neoul Sep 24, 2020
358c7c0
Updated prompt tab completion
neoul Sep 25, 2020
93fcc7a
Added dynamic suggestion for model
neoul Sep 25, 2020
ad1f6b1
Updated promptMode
neoul Sep 25, 2020
6a0a8c9
Updated README.md
neoul Sep 25, 2020
d4e4ea2
Added --dir, --file and --exclude flags to the prompt mode for single…
neoul Sep 25, 2020
7ff0061
Added gnmic prompt-mode history
neoul Oct 5, 2020
a4fbfde
Added change log file
neoul Oct 5, 2020
aed56df
Merge remote-tracking branch 'upstream/master'
neoul Oct 5, 2020
3ba799b
Removed .vscode
neoul Oct 5, 2020
736e4f3
Update path.go
neoul Oct 6, 2020
6111eba
Delete CHANGELOG.md
neoul Oct 6, 2020
7dd0f13
Updated code for less indentation
neoul Oct 6, 2020
85c10bb
Updated subcommand prompt
neoul Oct 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ _test/
builds/
dist
*.log
gnmic
*.tmp
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ gnmic -a 10.1.0.11:57400 -u admin -p admin --insecure \
gnmic -a 10.1.0.11:57400 -u admin -p admin --insecure \
sub --path "/state/port[port-id=1/1/c1/1]/statistics/in-packets"
```

### Prompt mode

The prompt mode is an interactive mode of the gnmic CLI client for user convenience.
The gnmic subcommands such as capabilities, get, set and subscribe of the gNMI protocol can be used in the prompt mode with tab completion for their flags and the xpath of the YANG data models that you defined.

![gnmic prompt-mode](docs/images/gnmic.prompt-mode.demo.gif)
5 changes: 2 additions & 3 deletions cmd/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ var printVersion bool
// capabilitiesCmd represents the capabilities command
var capabilitiesCmd = &cobra.Command{
Use: "capabilities",
Aliases: []string{"c", "cap"},
neoul marked this conversation as resolved.
Show resolved Hide resolved
Aliases: []string{"cap"},
Short: "query targets gnmi capabilities",

RunE: func(cmd *cobra.Command, args []string) error {
if viper.GetString("format") == "event" {
return fmt.Errorf("format event not supported for Capabilities RPC")
Expand All @@ -57,6 +56,7 @@ var capabilitiesCmd = &cobra.Command{
wg.Wait()
return nil
},
SilenceUsage: true,
}

func reqCapability(ctx context.Context, target *collector.Target, wg *sync.WaitGroup, lock *sync.Mutex) {
Expand Down Expand Up @@ -107,7 +107,6 @@ func reqCapability(ctx context.Context, target *collector.Target, wg *sync.WaitG

func init() {
rootCmd.AddCommand(capabilitiesCmd)
capabilitiesCmd.SilenceUsage = true
capabilitiesCmd.Flags().BoolVarP(&printVersion, "version", "", false, "show gnmi version only")
viper.BindPFlag("capabilities-version", capabilitiesCmd.LocalFlags().Lookup("version"))
}
38 changes: 26 additions & 12 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ var paths []string
var getCmd = &cobra.Command{
Use: "get",
Short: "run gnmi get on targets",
Annotations: map[string]string{
"--path": "XPATH",
"--prefix": "XPATH",
"--model": "MODEL",
},

RunE: func(cmd *cobra.Command, args []string) error {
if viper.GetString("format") == "event" {
Expand All @@ -59,6 +64,11 @@ var getCmd = &cobra.Command{
wg.Wait()
return nil
},
PostRun: func(cmd *cobra.Command, args []string) {
cmd.ResetFlags()
initGetFlags(cmd)
},
SilenceUsage: true,
}

func getRequest(ctx context.Context, req *gnmi.GetRequest, target *collector.Target, wg *sync.WaitGroup, lock *sync.Mutex) {
Expand Down Expand Up @@ -120,19 +130,23 @@ func getRequest(ctx context.Context, req *gnmi.GetRequest, target *collector.Tar

func init() {
rootCmd.AddCommand(getCmd)
getCmd.SilenceUsage = true
getCmd.Flags().StringArrayVarP(&paths, "path", "", []string{}, "get request paths")
getCmd.MarkFlagRequired("path")
getCmd.Flags().StringP("prefix", "", "", "get request prefix")
getCmd.Flags().StringSliceP("model", "", []string{}, "get request models")
getCmd.Flags().StringP("type", "t", "ALL", "data type requested from the target. one of: ALL, CONFIG, STATE, OPERATIONAL")
getCmd.Flags().StringP("target", "", "", "get request target")
initGetFlags(getCmd)
}

// used to init or reset getCmd flags for gnmic-prompt mode
func initGetFlags(cmd *cobra.Command) {
cmd.Flags().StringArrayVarP(&paths, "path", "", []string{}, "get request paths")
cmd.MarkFlagRequired("path")
cmd.Flags().StringP("prefix", "", "", "get request prefix")
cmd.Flags().StringSliceP("model", "", []string{}, "get request models")
cmd.Flags().StringP("type", "t", "ALL", "data type requested from the target. one of: ALL, CONFIG, STATE, OPERATIONAL")
cmd.Flags().StringP("target", "", "", "get request target")

viper.BindPFlag("get-path", getCmd.LocalFlags().Lookup("path"))
viper.BindPFlag("get-prefix", getCmd.LocalFlags().Lookup("prefix"))
viper.BindPFlag("get-model", getCmd.LocalFlags().Lookup("model"))
viper.BindPFlag("get-type", getCmd.LocalFlags().Lookup("type"))
viper.BindPFlag("get-target", getCmd.LocalFlags().Lookup("target"))
viper.BindPFlag("get-path", cmd.LocalFlags().Lookup("path"))
viper.BindPFlag("get-prefix", cmd.LocalFlags().Lookup("prefix"))
viper.BindPFlag("get-model", cmd.LocalFlags().Lookup("model"))
viper.BindPFlag("get-type", cmd.LocalFlags().Lookup("type"))
viper.BindPFlag("get-target", cmd.LocalFlags().Lookup("target"))
}

func createGetRequest() (*gnmi.GetRequest, error) {
Expand Down
3 changes: 1 addition & 2 deletions cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
var listenCmd = &cobra.Command{
Use: "listen",
Short: "listens for telemetry dialout updates from the node",

RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -114,11 +113,11 @@ var listenCmd = &cobra.Command{
defer server.grpcServer.Stop()
return nil
},
SilenceUsage: true,
}

func init() {
rootCmd.AddCommand(listenCmd)
listenCmd.SilenceUsage = true
listenCmd.Flags().Uint32P("max-concurrent-streams", "", 256, "max concurrent streams gnmic can receive per transport")

viper.BindPFlag("listen-max-concurrent-streams", listenCmd.LocalFlags().Lookup("max-concurrent-streams"))
Expand Down
Loading