Skip to content

Commit

Permalink
tweaks to skywire-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
林志宇 committed Apr 5, 2019
1 parent d4c3b69 commit 7840e3d
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 185 deletions.
12 changes: 0 additions & 12 deletions cmd/skywire-cli/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,7 +34,7 @@ func init() {

var entryCmd = &cobra.Command{
Use: "entry <node-public-key>",
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)
Expand Down
15 changes: 7 additions & 8 deletions cmd/skywire-cli/commands/node/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,7 +46,7 @@ var appsCmd = &cobra.Command{

var startAppCmd = &cobra.Command{
Use: "start-app <name>",
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]))
Expand All @@ -57,7 +56,7 @@ var startAppCmd = &cobra.Command{

var stopAppCmd = &cobra.Command{
Use: "stop-app <name>",
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]))
Expand All @@ -67,7 +66,7 @@ var stopAppCmd = &cobra.Command{

var setAppAutostartCmd = &cobra.Command{
Use: "set-app-autostart <name> (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
Expand Down
9 changes: 5 additions & 4 deletions cmd/skywire-cli/commands/node/gen-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ import (
"github.com/skycoin/skywire/pkg/node"
)

func init() {
RootCmd.AddCommand(genConfigCmd)
}

var (
output string
replace bool
configLocType = pathutil.WorkingDirLoc
)

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()))
}

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)
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/node/pk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
19 changes: 9 additions & 10 deletions cmd/skywire-cli/commands/node/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@ 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"
)

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)
Expand All @@ -40,7 +39,7 @@ var listRulesCmd = &cobra.Command{

var ruleCmd = &cobra.Command{
Use: "rule <route-id>",
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)
Expand All @@ -55,7 +54,7 @@ var ruleCmd = &cobra.Command{

var rmRuleCmd = &cobra.Command{
Use: "rm-rule <route-id>",
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)
Expand All @@ -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 <route-id> <remote-pk> <remote-port> <local-port> | fwd <next-route-id> <next-transport-id>)",
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 {
Expand Down
65 changes: 32 additions & 33 deletions cmd/skywire-cli/commands/node/transports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -43,25 +42,25 @@ 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)
printTransports(transports...)
},
}

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 <transport-id>",
Short: "returns summary of given transport by id",
var tpCmd = &cobra.Command{
Use: "tp <transport-id>",
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])
Expand All @@ -77,9 +76,15 @@ var (
timeout time.Duration
)

var addTransportCmd = &cobra.Command{
Use: "add-transport <remote-public-key>",
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 <remote-public-key>",
Short: "Adds a new transport",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
pk := internal.ParsePK("remote-public-key", args[0])
Expand All @@ -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 <transport-id>",
Short: "removes transport with given id",
var rmTpCmd = &cobra.Command{
Use: "rm-tp <transport-id>",
Short: "Removes transport with given id",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
tID := internal.ParseUUID("transport-id", args[0])
Expand Down
5 changes: 3 additions & 2 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
@@ -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{
Expand All @@ -24,5 +25,5 @@ func init() {

// Execute executes root CLI command.
func Execute() {
rootCmd.Execute() //nolint:errcheck
_ = rootCmd.Execute() //nolint:errcheck
}
Loading

0 comments on commit 7840e3d

Please sign in to comment.