diff --git a/cmd/skywire-cli/commands/node/node.go b/cmd/skywire-cli/commands/node/node.go new file mode 100644 index 0000000000..53cffe9705 --- /dev/null +++ b/cmd/skywire-cli/commands/node/node.go @@ -0,0 +1,15 @@ +package node + +import ( + "github.com/skycoin/skywire/cmd/skywire-cli/commands" + "github.com/spf13/cobra" +) + +var nodeCmd = &cobra.Command{ + Use: "node", + Short: "Commands that interact with the skywire-node", +} + +func init() { + commands.AddCommand(nodeCmd) +} diff --git a/cmd/skywire-cli/commands/pk.go b/cmd/skywire-cli/commands/node/pk.go similarity index 70% rename from cmd/skywire-cli/commands/pk.go rename to cmd/skywire-cli/commands/node/pk.go index 91c2e5f346..9ce9dc3789 100644 --- a/cmd/skywire-cli/commands/pk.go +++ b/cmd/skywire-cli/commands/node/pk.go @@ -1,13 +1,15 @@ -package commands +package node import ( "fmt" + "log" + "github.com/skycoin/skywire/cmd/skywire-cli/commands" "github.com/spf13/cobra" ) func init() { - rootCmd.AddCommand(pkCmd) + nodeCmd.AddCommand(pkCmd) } var pkCmd = &cobra.Command{ @@ -15,7 +17,7 @@ var pkCmd = &cobra.Command{ Short: "get public key of node", Run: func(_ *cobra.Command, _ []string) { - client := rpcClient() + client := commands.PrpcClient() summary, err := client.Summary() if err != nil { log.Fatal("Failed to connect:", err) diff --git a/cmd/skywire-cli/commands/root.go b/cmd/skywire-cli/commands/root.go index e184bf05f3..08f8742e35 100644 --- a/cmd/skywire-cli/commands/root.go +++ b/cmd/skywire-cli/commands/root.go @@ -36,6 +36,22 @@ func rpcClient() node.RPCClient { return node.NewRPCClient(client, node.RPCPrefix) } +// PrpcClient exported rpc method that +func PrpcClient() node.RPCClient { + client, err := rpc.Dial("tcp", rpcAddr) + if err != nil { + log.Fatal("RPC connection failed:", err) + } + return node.NewRPCClient(client, node.RPCPrefix) +} + +// AddCommand adds commands to the root command +func AddCommand(command *cobra.Command) { + rootCmd.AddCommand( + command, + ) +} + func catch(err error, msgs ...string) { if err != nil { if len(msgs) > 0 { diff --git a/cmd/skywire-cli/skywire-cli.go b/cmd/skywire-cli/skywire-cli.go index 7a3aa2c1ea..002bd09e3c 100644 --- a/cmd/skywire-cli/skywire-cli.go +++ b/cmd/skywire-cli/skywire-cli.go @@ -3,7 +3,10 @@ CLI for skywire node */ package main -import "github.com/skycoin/skywire/cmd/skywire-cli/commands" +import ( + "github.com/skycoin/skywire/cmd/skywire-cli/commands" + _ "github.com/skycoin/skywire/cmd/skywire-cli/commands/node" +) func main() { commands.Execute()