Skip to content

Commit

Permalink
restructured cli commands package
Browse files Browse the repository at this point in the history
  • Loading branch information
mungujn committed Apr 2, 2019
1 parent 5569e50 commit c1f80bd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
15 changes: 15 additions & 0 deletions cmd/skywire-cli/commands/node/node.go
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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{
Use: "pk",
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)
Expand Down
16 changes: 16 additions & 0 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/skywire-cli/skywire-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c1f80bd

Please sign in to comment.