diff --git a/cmd/skywire-cli/README.md b/cmd/skywire-cli/README.md deleted file mode 100644 index aa7d1cbb4f..0000000000 --- a/cmd/skywire-cli/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# CLI for skywire node - -skywire-cli implements management commands for skywire node via -RPC interface. - -## Available commands - -- node - |Sub command|Details| - |-----------|-------| - |add-rule |adds a new routing rule| - | \ No newline at end of file diff --git a/cmd/skywire-cli/commands/mdisc/mdisc.go b/cmd/skywire-cli/commands/mdisc/root.go similarity index 88% rename from cmd/skywire-cli/commands/mdisc/mdisc.go rename to cmd/skywire-cli/commands/mdisc/root.go index 5e62733ee4..876e8098e9 100644 --- a/cmd/skywire-cli/commands/mdisc/mdisc.go +++ b/cmd/skywire-cli/commands/mdisc/root.go @@ -10,21 +10,22 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/messaging-discovery/client" ) -// RootCmd contains commands that interact with messaging services -var RootCmd = &cobra.Command{ - Use: "mdisc", - Short: "Commands that interact with messaging-discovery", -} - var mdAddr string func init() { RootCmd.PersistentFlags().StringVar(&mdAddr, "addr", "https://messaging.discovery.skywire.skycoin.net", "address of messaging discovery server") +} +// RootCmd is the command that contains sub-commands which interacts with messaging services. +var RootCmd = &cobra.Command{ + Use: "mdisc", + Short: "Contains sub-commands that interact with a remote Messaging Discovery", +} + +func init() { RootCmd.AddCommand( entryCmd, availableServersCmd, @@ -33,7 +34,7 @@ func init() { var entryCmd = &cobra.Command{ Use: "entry ", - Short: "fetch entry from messaging-discovery", + Short: "fetches an entry from messaging-discovery", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) diff --git a/cmd/skywire-cli/commands/node/app.go b/cmd/skywire-cli/commands/node/app.go index e4a7ffb089..23d3092341 100644 --- a/cmd/skywire-cli/commands/node/app.go +++ b/cmd/skywire-cli/commands/node/app.go @@ -9,22 +9,21 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/node" ) func init() { RootCmd.AddCommand( - appsCmd, + lsAppsCmd, startAppCmd, stopAppCmd, setAppAutostartCmd, ) } -var appsCmd = &cobra.Command{ - Use: "apps", - Short: "lists apps running on the node", +var lsAppsCmd = &cobra.Command{ + Use: "ls-apps", + Short: "Lists apps running on the local node", Run: func(_ *cobra.Command, _ []string) { states, err := rpcClient().Apps() internal.Catch(err) @@ -47,7 +46,7 @@ var appsCmd = &cobra.Command{ var startAppCmd = &cobra.Command{ Use: "start-app ", - Short: "starts an app of given name", + Short: "Starts an app of given name", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { internal.Catch(rpcClient().StartApp(args[0])) @@ -57,7 +56,7 @@ var startAppCmd = &cobra.Command{ var stopAppCmd = &cobra.Command{ Use: "stop-app ", - Short: "stops an app of given name", + Short: "Stops an app of given name", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { internal.Catch(rpcClient().StopApp(args[0])) @@ -67,7 +66,7 @@ var stopAppCmd = &cobra.Command{ var setAppAutostartCmd = &cobra.Command{ Use: "set-app-autostart (on|off)", - Short: "sets the autostart flag for an app of given name", + Short: "Sets the autostart flag for an app of given name", Args: cobra.MinimumNArgs(2), Run: func(_ *cobra.Command, args []string) { var autostart bool diff --git a/cmd/skywire-cli/commands/node/gen-config.go b/cmd/skywire-cli/commands/node/gen-config.go index 10cc884d12..220b572574 100644 --- a/cmd/skywire-cli/commands/node/gen-config.go +++ b/cmd/skywire-cli/commands/node/gen-config.go @@ -12,6 +12,10 @@ import ( "github.com/skycoin/skywire/pkg/node" ) +func init() { + RootCmd.AddCommand(genConfigCmd) +} + var ( output string replace bool @@ -19,7 +23,6 @@ var ( ) func init() { - RootCmd.AddCommand(genConfigCmd) genConfigCmd.Flags().StringVarP(&output, "output", "o", "", "path of output config file. Uses default of 'type' flag if unspecified.") genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, "whether to allow rewrite of a file that already exists.") genConfigCmd.Flags().VarP(&configLocType, "type", "m", fmt.Sprintf("config generation mode. Valid values: %v", pathutil.AllConfigLocationTypes())) @@ -27,7 +30,7 @@ func init() { var genConfigCmd = &cobra.Command{ Use: "gen-config", - Short: "Generate default config file", + Short: "Generates a config file", PreRun: func(_ *cobra.Command, _ []string) { if output == "" { output = pathutil.NodeDefaults().Get(configLocType) @@ -59,7 +62,6 @@ func homeConfig() *node.Config { c.AppsPath = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/apps") c.Transport.LogStore.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/transport_logs") c.Routing.Table.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/routing.db") - return c } @@ -68,7 +70,6 @@ func localConfig() *node.Config { c.AppsPath = "/usr/local/skycoin/skywire/apps" c.Transport.LogStore.Location = "/usr/local/skycoin/skywire/transport_logs" c.Routing.Table.Location = "/usr/local/skycoin/skywire/routing.db" - return c } diff --git a/cmd/skywire-cli/commands/node/pk.go b/cmd/skywire-cli/commands/node/pk.go index 44c5d62be4..f87379b9e1 100644 --- a/cmd/skywire-cli/commands/node/pk.go +++ b/cmd/skywire-cli/commands/node/pk.go @@ -12,7 +12,7 @@ func init() { var pkCmd = &cobra.Command{ Use: "pk", - Short: "get public key of node", + Short: "Obtains the public key of the node", Run: func(_ *cobra.Command, _ []string) { client := rpcClient() diff --git a/cmd/skywire-cli/commands/node/node.go b/cmd/skywire-cli/commands/node/root.go similarity index 88% rename from cmd/skywire-cli/commands/node/node.go rename to cmd/skywire-cli/commands/node/root.go index 68076c625f..f6fbf18bf8 100644 --- a/cmd/skywire-cli/commands/node/node.go +++ b/cmd/skywire-cli/commands/node/root.go @@ -1,28 +1,28 @@ package node import ( + "net/rpc" + "github.com/skycoin/skycoin/src/util/logging" "github.com/spf13/cobra" - "net/rpc" - "github.com/skycoin/skywire/pkg/node" ) var log = logging.MustGetLogger("skywire-cli") -// RootCmd contains commands that interact with the skywire-node -var RootCmd = &cobra.Command{ - Use: "node", - Short: "Commands that interact with the skywire-node", -} - var rpcAddr string func init() { RootCmd.PersistentFlags().StringVarP(&rpcAddr, "rpc", "", "localhost:3435", "RPC server address") } +// RootCmd contains commands that interact with the skywire-node +var RootCmd = &cobra.Command{ + Use: "node", + Short: "Contains sub-commands that interact with the local Skywire (App) Node", +} + func rpcClient() node.RPCClient { client, err := rpc.Dial("tcp", rpcAddr) if err != nil { diff --git a/cmd/skywire-cli/commands/node/routes.go b/cmd/skywire-cli/commands/node/routes.go index 4cd4a53993..b80c3ab49c 100644 --- a/cmd/skywire-cli/commands/node/routes.go +++ b/cmd/skywire-cli/commands/node/routes.go @@ -12,7 +12,6 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/node" "github.com/skycoin/skywire/pkg/router" "github.com/skycoin/skywire/pkg/routing" @@ -20,16 +19,16 @@ import ( func init() { RootCmd.AddCommand( - listRulesCmd, + lsRulesCmd, ruleCmd, rmRuleCmd, addRuleCmd, ) } -var listRulesCmd = &cobra.Command{ - Use: "list-rules", - Short: "lists the local node's routing rules", +var lsRulesCmd = &cobra.Command{ + Use: "ls-rules", + Short: "Lists the local node's routing rules", Run: func(_ *cobra.Command, _ []string) { rules, err := rpcClient().RoutingRules() internal.Catch(err) @@ -40,7 +39,7 @@ var listRulesCmd = &cobra.Command{ var ruleCmd = &cobra.Command{ Use: "rule ", - Short: "returns a routing rule via route ID key", + Short: "Returns a routing rule via route ID key", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { id, err := strconv.ParseUint(args[0], 10, 32) @@ -55,7 +54,7 @@ var ruleCmd = &cobra.Command{ var rmRuleCmd = &cobra.Command{ Use: "rm-rule ", - Short: "removes a routing rule via route ID key", + Short: "Removes a routing rule via route ID key", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { id, err := strconv.ParseUint(args[0], 10, 32) @@ -65,15 +64,15 @@ var rmRuleCmd = &cobra.Command{ }, } +var expire time.Duration + func init() { addRuleCmd.PersistentFlags().DurationVar(&expire, "expire", router.RouteTTL, "duration after which routing rule will expire") } -var expire time.Duration - var addRuleCmd = &cobra.Command{ Use: "add-rule (app | fwd )", - Short: "adds a new routing rule", + Short: "Adds a new routing rule", Args: func(_ *cobra.Command, args []string) error { if len(args) > 0 { switch rt := args[0]; rt { diff --git a/cmd/skywire-cli/commands/node/transports.go b/cmd/skywire-cli/commands/node/transports.go index bbdc24fa79..4fbc0cf412 100644 --- a/cmd/skywire-cli/commands/node/transports.go +++ b/cmd/skywire-cli/commands/node/transports.go @@ -10,24 +10,23 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/cipher" "github.com/skycoin/skywire/pkg/node" ) func init() { RootCmd.AddCommand( - transportTypesCmd, - listTransportsCmd, - transportCmd, - addTransportCmd, - rmTransportCmd, + lsTypesCmd, + lsTpCmd, + tpCmd, + addTpCmd, + rmTpCmd, ) } -var transportTypesCmd = &cobra.Command{ - Use: "transport-types", - Short: "lists transport types used by the local node", +var lsTypesCmd = &cobra.Command{ + Use: "ls-types", + Short: "Lists transport types used by the local node", Run: func(_ *cobra.Command, _ []string) { types, err := rpcClient().TransportTypes() internal.Catch(err) @@ -43,9 +42,15 @@ var ( showLogs bool ) -var listTransportsCmd = &cobra.Command{ - Use: "list-transports", - Short: "lists the available transports with optional filter flags", +func init() { + lsTpCmd.Flags().StringSliceVar(&filterTypes, "filter-types", filterTypes, "comma-separated; if specified, only shows transports of given types") + lsTpCmd.Flags().Var(&filterPubKeys, "filter-pks", "comma-separated; if specified, only shows transports associated with given nodes") + lsTpCmd.Flags().BoolVar(&showLogs, "show-logs", true, "whether to show transport logs in output") +} + +var lsTpCmd = &cobra.Command{ + Use: "ls-tp", + Short: "Lists the available transports with optional filter flags", Run: func(_ *cobra.Command, _ []string) { transports, err := rpcClient().Transports(filterTypes, filterPubKeys, showLogs) internal.Catch(err) @@ -53,15 +58,9 @@ var listTransportsCmd = &cobra.Command{ }, } -func init() { - listTransportsCmd.Flags().StringSliceVar(&filterTypes, "filter-types", filterTypes, "comma-separated; if specified, only shows transports of given types") - listTransportsCmd.Flags().Var(&filterPubKeys, "filter-pks", "comma-separated; if specified, only shows transports associated with given nodes") - listTransportsCmd.Flags().BoolVar(&showLogs, "show-logs", true, "whether to show transport logs in output") -} - -var transportCmd = &cobra.Command{ - Use: "transport ", - Short: "returns summary of given transport by id", +var tpCmd = &cobra.Command{ + Use: "tp ", + Short: "Returns summary of given transport by id", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { tpID := internal.ParseUUID("transport-id", args[0]) @@ -77,9 +76,15 @@ var ( timeout time.Duration ) -var addTransportCmd = &cobra.Command{ - Use: "add-transport ", - Short: "adds a new transport", +func init() { + addTpCmd.Flags().StringVar(&transportType, "type", "messaging", "type of transport to add") + addTpCmd.Flags().BoolVar(&public, "public", true, "whether to make the transport public") + addTpCmd.Flags().DurationVarP(&timeout, "timeout", "t", 0, "if specified, sets an operation timeout") +} + +var addTpCmd = &cobra.Command{ + Use: "add-tp ", + Short: "Adds a new transport", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { pk := internal.ParsePK("remote-public-key", args[0]) @@ -89,15 +94,9 @@ var addTransportCmd = &cobra.Command{ }, } -func init() { - addTransportCmd.Flags().StringVar(&transportType, "type", "messaging", "type of transport to add") - addTransportCmd.Flags().BoolVar(&public, "public", true, "whether to make the transport public") - addTransportCmd.Flags().DurationVarP(&timeout, "timeout", "t", 0, "if specified, sets an operation timeout") -} - -var rmTransportCmd = &cobra.Command{ - Use: "rm-transport ", - Short: "removes transport with given id", +var rmTpCmd = &cobra.Command{ + Use: "rm-tp ", + Short: "Removes transport with given id", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { tID := internal.ParseUUID("transport-id", args[0]) diff --git a/cmd/skywire-cli/commands/root.go b/cmd/skywire-cli/commands/root.go index 3e27939cd0..c08a222bc2 100644 --- a/cmd/skywire-cli/commands/root.go +++ b/cmd/skywire-cli/commands/root.go @@ -1,11 +1,12 @@ package commands import ( + "github.com/spf13/cobra" + "github.com/skycoin/skywire/cmd/skywire-cli/commands/mdisc" "github.com/skycoin/skywire/cmd/skywire-cli/commands/node" "github.com/skycoin/skywire/cmd/skywire-cli/commands/rtfind" "github.com/skycoin/skywire/cmd/skywire-cli/commands/tpdisc" - "github.com/spf13/cobra" ) var rootCmd = &cobra.Command{ @@ -24,5 +25,5 @@ func init() { // Execute executes root CLI command. func Execute() { - rootCmd.Execute() //nolint:errcheck + _ = rootCmd.Execute() //nolint:errcheck } diff --git a/cmd/skywire-cli/commands/rtfind/root.go b/cmd/skywire-cli/commands/rtfind/root.go new file mode 100644 index 0000000000..fcb0bfeda8 --- /dev/null +++ b/cmd/skywire-cli/commands/rtfind/root.go @@ -0,0 +1,40 @@ +package rtfind + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/skycoin/skywire/cmd/skywire-cli/internal" + "github.com/skycoin/skywire/pkg/cipher" + "github.com/skycoin/skywire/pkg/route-finder/client" +) + +var frAddr string +var frMinHops, frMaxHops uint16 + +func init() { + RootCmd.Flags().StringVar(&frAddr, "addr", "https://routefinder.skywire.skycoin.net", "address in which to contact route finder service") + RootCmd.Flags().Uint16Var(&frMinHops, "min-hops", 1, "min hops for the returning routeFinderRoutesCmd") + RootCmd.Flags().Uint16Var(&frMaxHops, "max-hops", 1000, "max hops for the returning routeFinderRoutesCmd") +} + +// RootCmd is the command that queries the route-finder. +var RootCmd = &cobra.Command{ + Use: "rtfind ", + Short: "Queries the Route Finder for available routes between two nodes", + Args: cobra.MinimumNArgs(2), + Run: func(_ *cobra.Command, args []string) { + rfc := client.NewHTTP(frAddr) + + var srcPK, dstPK cipher.PubKey + internal.Catch(srcPK.Set(args[0])) + internal.Catch(dstPK.Set(args[1])) + + forward, reverse, err := rfc.PairedRoutes(srcPK, dstPK, frMinHops, frMaxHops) + internal.Catch(err) + + fmt.Println("forward: ", forward) + fmt.Println("reverse: ", reverse) + }, +} diff --git a/cmd/skywire-cli/commands/rtfind/rtfind.go b/cmd/skywire-cli/commands/rtfind/rtfind.go deleted file mode 100644 index 8861ff9ef8..0000000000 --- a/cmd/skywire-cli/commands/rtfind/rtfind.go +++ /dev/null @@ -1,52 +0,0 @@ -package rtfind - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/skycoin/skywire/cmd/skywire-cli/internal" - - "github.com/skycoin/skywire/pkg/cipher" - "github.com/skycoin/skywire/pkg/route-finder/client" -) - -// RootCmd contains commands that interact with the route finder -var RootCmd = &cobra.Command{ - Use: "rtfind", - Short: "Commands that interact with the route-finder", -} - -func init() { - RootCmd.AddCommand( - findRoutesCmd, - ) -} - -var frAddr string -var frMinHops, frMaxHops uint16 - -var findRoutesCmd = &cobra.Command{ - Use: "find-routes ", - Short: "lists available routes between two nodes via route finder service", - Args: cobra.MinimumNArgs(2), - Run: func(_ *cobra.Command, args []string) { - rfc := client.NewHTTP(frAddr) - - var srcPK, dstPK cipher.PubKey - internal.Catch(srcPK.Set(args[0])) - internal.Catch(dstPK.Set(args[1])) - - forward, reverse, err := rfc.PairedRoutes(srcPK, dstPK, frMinHops, frMaxHops) - internal.Catch(err) - - fmt.Println("forward: ", forward) - fmt.Println("reverse: ", reverse) - }, -} - -func init() { - findRoutesCmd.Flags().StringVar(&frAddr, "addr", "https://routefinder.skywire.skycoin.net", "address in which to contact route finder service") - findRoutesCmd.Flags().Uint16Var(&frMinHops, "min-hops", 1, "min hops for the returning routeFinderRoutesCmd") - findRoutesCmd.Flags().Uint16Var(&frMaxHops, "max-hops", 1000, "max hops for the returning routeFinderRoutesCmd") -} diff --git a/cmd/skywire-cli/commands/tpdisc/tpdisc.go b/cmd/skywire-cli/commands/tpdisc/root.go similarity index 65% rename from cmd/skywire-cli/commands/tpdisc/tpdisc.go rename to cmd/skywire-cli/commands/tpdisc/root.go index 266c5f3363..e0fb6399df 100644 --- a/cmd/skywire-cli/commands/tpdisc/tpdisc.go +++ b/cmd/skywire-cli/commands/tpdisc/root.go @@ -12,33 +12,27 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/cipher" "github.com/skycoin/skywire/pkg/transport" "github.com/skycoin/skywire/pkg/transport-discovery/client" ) -// RootCmd contains commands that interact with transport-discovery -var RootCmd = &cobra.Command{ - Use: "tpdisc", - Short: "Commands that interact with transport-discovery", -} - -func init() { - RootCmd.AddCommand( - findTransport, - ) -} - var ( addr string tpID transportID tpPK cipher.PubKey ) -var findTransport = &cobra.Command{ - Use: "find-transport (--id= | --pk=)", - Short: "finds and lists transport(s) of given transport ID or edge public key from transport discovery", +func init() { + RootCmd.Flags().StringVar(&addr, "addr", "https://transport.discovery.skywire.skycoin.net", "address of transport discovery") + RootCmd.Flags().Var(&tpID, "id", "if specified, obtains a single transport of given ID") + RootCmd.Flags().Var(&tpPK, "pk", "if specified, obtains transports associated with given public key") +} + +// RootCmd is the command that queries the transport-discovery. +var RootCmd = &cobra.Command{ + Use: "tpdisc (--id= | --pk=)", + Short: "Queries the Transport Discovery to find transport(s) of given transport ID or edge public key", Args: func(_ *cobra.Command, _ []string) error { var ( nilID = uuid.UUID(tpID) == (uuid.UUID{}) @@ -70,12 +64,6 @@ var findTransport = &cobra.Command{ }, } -func init() { - findTransport.Flags().StringVar(&addr, "addr", "https://transport.discovery.skywire.skycoin.net", "address of transport discovery") - findTransport.Flags().Var(&tpID, "id", "if specified, obtains a single transport of given ID") - findTransport.Flags().Var(&tpPK, "pk", "if specified, obtains transports associated with given public key") -} - func printTransportEntries(entries ...*transport.EntryWithStatus) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent) _, err := fmt.Fprintln(w, "id\ttype\tpublic\tregistered\tup\tedge1\tedge2\topinion1\topinion2") @@ -87,3 +75,21 @@ func printTransportEntries(entries ...*transport.EntryWithStatus) { } internal.Catch(w.Flush()) } + +type transportID uuid.UUID + +// String implements pflag.Value +func (t transportID) String() string { return uuid.UUID(t).String() } + +// Type implements pflag.Value +func (transportID) Type() string { return "transportID" } + +// Set implements pflag.Value +func (t *transportID) Set(s string) error { + tID, err := uuid.Parse(s) + if err != nil { + return err + } + *t = transportID(tID) + return nil +} diff --git a/cmd/skywire-cli/commands/tpdisc/transport.go b/cmd/skywire-cli/commands/tpdisc/transport.go deleted file mode 100644 index e1570afb81..0000000000 --- a/cmd/skywire-cli/commands/tpdisc/transport.go +++ /dev/null @@ -1,23 +0,0 @@ -package tpdisc - -import ( - "github.com/google/uuid" -) - -type transportID uuid.UUID - -// String implements pflag.Value -func (t transportID) String() string { return uuid.UUID(t).String() } - -// Type implements pflag.Value -func (transportID) Type() string { return "transportID" } - -// Set implements pflag.Value -func (t *transportID) Set(s string) error { - tID, err := uuid.Parse(s) - if err != nil { - return err - } - *t = transportID(tID) - return nil -} diff --git a/cmd/skywire-cli/internal/internal.go b/cmd/skywire-cli/internal/internal.go index 3bbd3df576..0557eae116 100644 --- a/cmd/skywire-cli/internal/internal.go +++ b/cmd/skywire-cli/internal/internal.go @@ -4,10 +4,9 @@ import ( "fmt" "github.com/google/uuid" + "github.com/skycoin/skycoin/src/util/logging" "github.com/skycoin/skywire/pkg/cipher" - - "github.com/skycoin/skycoin/src/util/logging" ) var log = logging.MustGetLogger("skywire-cli")