Skip to content
Snippets Groups Projects
Commit 86bd45d2 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

improve cli documentation

parent 81ceceea
No related branches found
No related tags found
1 merge request!133Rewrite readme
...@@ -40,7 +40,10 @@ import ( ...@@ -40,7 +40,10 @@ import (
var addDeviceCmd = &cobra.Command{ var addDeviceCmd = &cobra.Command{
Use: "add-device", Use: "add-device",
Short: "adds a device to the controller", Short: "adds a device to the controller",
Long: ``, Long: `Adds a device to the controller.
Device address and user credentials need to be provided
if they diverge from the default credentials.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet( return cli.HTTPGet(
apiEndpoint, apiEndpoint,
......
...@@ -41,7 +41,7 @@ var capabilitiesCmd = &cobra.Command{ ...@@ -41,7 +41,7 @@ var capabilitiesCmd = &cobra.Command{
Use: "capabilities", Use: "capabilities",
Short: "capabilities request", Short: "capabilities request",
Long: `Sends a gNMI Capabilities request to the specified target Long: `Sends a gNMI Capabilities request to the specified target
// and prints the supported models to stdout.`, and prints the supported models to stdout.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.Capabilities(username, password, address) return cli.Capabilities(username, password, address)
}, },
......
...@@ -42,8 +42,9 @@ var apiEndpoint string ...@@ -42,8 +42,9 @@ var apiEndpoint string
// cliCmd represents the cli command // cliCmd represents the cli command
var cliCmd = &cobra.Command{ var cliCmd = &cobra.Command{
Use: "cli", Use: "cli",
Short: "", Short: "initialises the cli",
Long: ``, Long: `Initialises the CLI. The first PND UUID and SBI UUID
are written to the config file for subsequent requests.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(apiEndpoint, "init") return cli.HTTPGet(apiEndpoint, "init")
}, },
...@@ -52,7 +53,6 @@ var cliCmd = &cobra.Command{ ...@@ -52,7 +53,6 @@ var cliCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(cliCmd) rootCmd.AddCommand(cliCmd)
cliCmd.PersistentFlags().StringVar(&uuid, "uuid", "", "uuid of the requested device")
cliCmd.PersistentFlags().StringVar(&apiEndpoint, "api-endpoint", "http://gosdn-develop.apps.ocp.fbi.h-da.de/api", "address of the target") cliCmd.PersistentFlags().StringVar(&apiEndpoint, "api-endpoint", "http://gosdn-develop.apps.ocp.fbi.h-da.de/api", "address of the target")
} }
...@@ -39,8 +39,10 @@ import ( ...@@ -39,8 +39,10 @@ import (
// cliSetCmd represents the cliSet command // cliSetCmd represents the cliSet command
var cliSetCmd = &cobra.Command{ var cliSetCmd = &cobra.Command{
Use: "set", Use: "set",
Args: cobra.ExactArgs(2),
Short: "set a value on a device", Short: "set a value on a device",
Long: ``, Long: `Set a path value for a given device. Only one path and
only one value supported for now`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet( return cli.HTTPGet(
apiEndpoint, apiEndpoint,
...@@ -57,4 +59,6 @@ var cliSetCmd = &cobra.Command{ ...@@ -57,4 +59,6 @@ var cliSetCmd = &cobra.Command{
func init() { func init() {
cliCmd.AddCommand(cliSetCmd) cliCmd.AddCommand(cliSetCmd)
cliCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device")
} }
...@@ -40,7 +40,8 @@ import ( ...@@ -40,7 +40,8 @@ import (
var getCmd = &cobra.Command{ var getCmd = &cobra.Command{
Use: "gosdn get", Use: "gosdn get",
Short: "get request", Short: "get request",
Long: `Sends a gNMI Get request to the specified target and prints the response to stdout`, Long: `Sends a gNMI Get request to the specified target and
prints the response to stdout`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
_, err := cli.Get(address, username, password, args...) _, err := cli.Get(address, username, password, args...)
return err return err
......
...@@ -39,13 +39,16 @@ import ( ...@@ -39,13 +39,16 @@ import (
// getDeviceCmd represents the getDevice command // getDeviceCmd represents the getDevice command
var getDeviceCmd = &cobra.Command{ var getDeviceCmd = &cobra.Command{
Use: "get-device", Use: "get-device",
Args: cobra.ExactArgs(1),
Short: "gets device information from the controller", Short: "gets device information from the controller",
Long: ``, Long: `Gets device information from the controller.
Device UUID needs to be specified as positional argument.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet( return cli.HTTPGet(
apiEndpoint, apiEndpoint,
"getDevice", "getDevice",
"uuid="+uuid, "uuid="+args[0],
"sbi="+cliSbi, "sbi="+cliSbi,
"pnd="+cliPnd, "pnd="+cliPnd,
) )
......
...@@ -40,7 +40,7 @@ import ( ...@@ -40,7 +40,7 @@ import (
var getIdsCmd = &cobra.Command{ var getIdsCmd = &cobra.Command{
Use: "get-ids", Use: "get-ids",
Short: "gets device IDs from the controller", Short: "gets device IDs from the controller",
Long: ``, Long: `Gets device IDs from the controller and lists them.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(apiEndpoint, "getIDs") return cli.HTTPGet(apiEndpoint, "getIDs")
}, },
......
...@@ -40,7 +40,9 @@ import ( ...@@ -40,7 +40,9 @@ import (
var initCmd = &cobra.Command{ var initCmd = &cobra.Command{
Use: "init", Use: "init",
Short: "initialise SBI and PND", Short: "initialise SBI and PND",
Long: ``, Long: `Initialise SBI and PND and saves values to config file.
Same as invoking "gosdn cli" without any arguments`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(apiEndpoint, "init") return cli.HTTPGet(apiEndpoint, "init")
}, },
......
...@@ -39,8 +39,11 @@ import ( ...@@ -39,8 +39,11 @@ import (
// requestCmd represents the request command // requestCmd represents the request command
var requestCmd = &cobra.Command{ var requestCmd = &cobra.Command{
Use: "request", Use: "request",
Args: cobra.ExactArgs(1),
Short: "requests a path from a specified device on the controller", Short: "requests a path from a specified device on the controller",
Long: ``, Long: `Requests a path from a specified device on the controller.
The request path is passed as positional argument.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet( return cli.HTTPGet(
apiEndpoint, apiEndpoint,
...@@ -55,4 +58,6 @@ var requestCmd = &cobra.Command{ ...@@ -55,4 +58,6 @@ var requestCmd = &cobra.Command{
func init() { func init() {
cliCmd.AddCommand(requestCmd) cliCmd.AddCommand(requestCmd)
cliCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device")
} }
...@@ -39,8 +39,12 @@ import ( ...@@ -39,8 +39,12 @@ import (
// requestAllCmd represents the requestAll command // requestAllCmd represents the requestAll command
var requestAllCmd = &cobra.Command{ var requestAllCmd = &cobra.Command{
Use: "request-all", Use: "request-all",
Args: cobra.ExactArgs(1),
Short: "requests specified path from all devices on the controller", Short: "requests specified path from all devices on the controller",
Long: ``, Long: `Requests a path from all devices on the controller known by
the controller.
The request path is passed as positional argument.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet( return cli.HTTPGet(
apiEndpoint, apiEndpoint,
......
...@@ -32,11 +32,12 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -32,11 +32,12 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd package cmd
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"context" "context"
"os"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
...@@ -54,7 +55,8 @@ var cliSbi string ...@@ -54,7 +55,8 @@ var cliSbi string
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "gosdn", Use: "gosdn",
Short: "starts the gosdn controller", Short: "starts the gosdn controller",
Long: `Set GOSDN_DEBUG environment variable to enable debug logging.`, Long: `Starts the gosdn controller and listens on port 8080
for REST API calls.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
...@@ -74,10 +76,6 @@ func Execute() { ...@@ -74,10 +76,6 @@ func Execute() {
func init() { func init() {
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./configs/gosdn.toml)") rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./configs/gosdn.toml)")
rootCmd.PersistentFlags().StringVarP(&username, "username", "u", "admin", "username for a gnmi resource") rootCmd.PersistentFlags().StringVarP(&username, "username", "u", "admin", "username for a gnmi resource")
rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "arista", "password for a gnmi resource") rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "arista", "password for a gnmi resource")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment