Skip to content

Commit

Permalink
Add app arg cli subcommand (#1356)
Browse files Browse the repository at this point in the history
* Add new subcommand arg to visor app

Thic commit contains the new subcommand arg which is used to change various args of the apps.

This subcommand setAppAutostartCmd which was previously directly under app is now also moved under arg.

The other commands contains setAppAutostartCmd, setAppKillswitchCmd and setAppSecureCmd whcih take the app name and on/off as arguemnts.

The subcommands setAppPasscodeCmd and setAppNetworkInterfaceCmd take app name and a string as their args and have a special arg named remove that removes the arg from the said app.

* Minor change

* Add changelog

* Minor changes
  • Loading branch information
ersonp authored Sep 14, 2022
1 parent cdcb233 commit a3e4954
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 1.2.0

### Added
- `skywire-cli` subcommand `arg` under `visor app` [#1356](https://github.com/skycoin/skywire/pull/1356)

### Changed
- moved `skywire-cli` subcommand `autoconnect` from `visor app` to `visor app arg` [#1356](https://github.com/skycoin/skywire/pull/1356)

### Removed

Expand Down
90 changes: 84 additions & 6 deletions cmd/skywire-cli/commands/visor/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ func init() {
lsAppsCmd,
startAppCmd,
stopAppCmd,
setAppAutostartCmd,
appLogsSinceCmd,
argCmd,
)
argCmd.AddCommand(
setAppAutostartCmd,
setAppKillswitchCmd,
setAppSecureCmd,
setAppPasscodeCmd,
setAppNetworkInterfaceCmd,
)
}

var argCmd = &cobra.Command{
Use: "arg",
Short: "App args",
}

var appCmd = &cobra.Command{
Use: "app",
Short: "App settings",
Expand Down Expand Up @@ -98,15 +110,15 @@ var stopAppCmd = &cobra.Command{
}

var setAppAutostartCmd = &cobra.Command{
Use: "autostart <name> (on|off)",
Short: "Autostart app",
Use: "autostart <name> (true|false)",
Short: "Set app autostart",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var autostart bool
switch args[1] {
case "on":
case "true":
autostart = true
case "off":
case "false":
autostart = false
default:
internal.Catch(cmd.Flags(), fmt.Errorf("invalid args[1] value: %s", args[1]))
Expand All @@ -116,9 +128,75 @@ var setAppAutostartCmd = &cobra.Command{
},
}

var setAppKillswitchCmd = &cobra.Command{
Use: "killswitch <name> (true|false)",
Short: "Set app killswitch",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var killswitch bool
switch args[1] {
case "true":
killswitch = true
case "false":
killswitch = false
default:
internal.Catch(cmd.Flags(), fmt.Errorf("invalid args[1] value: %s", args[1]))
}
internal.Catch(cmd.Flags(), clirpc.Client().SetAppKillswitch(args[0], killswitch))
internal.PrintOutput(cmd.Flags(), "OK", "OK\n")
},
}

var setAppSecureCmd = &cobra.Command{
Use: "secure <name> (true|false)",
Short: "Set app secure",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var secure bool
switch args[1] {
case "true":
secure = true
case "false":
secure = false
default:
internal.Catch(cmd.Flags(), fmt.Errorf("invalid args[1] value: %s", args[1]))
}
internal.Catch(cmd.Flags(), clirpc.Client().SetAppSecure(args[0], secure))
internal.PrintOutput(cmd.Flags(), "OK", "OK\n")
},
}

var setAppPasscodeCmd = &cobra.Command{
Use: "passcode <name> <passcode>",
Short: "Set app passcode.\n\"remove\" is a special arg to remove the passcode",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
passcode := args[1]
if args[1] == "remove" {
passcode = ""
}
internal.Catch(cmd.Flags(), clirpc.Client().SetAppPassword(args[0], passcode))
internal.PrintOutput(cmd.Flags(), "OK", "OK\n")
},
}

var setAppNetworkInterfaceCmd = &cobra.Command{
Use: "netifc <name> <interface>",
Short: "Set app network interface.\n\"remove\" is a special arg to remove the netifc",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
netifc := args[1]
if args[1] == "remove" {
netifc = ""
}
internal.Catch(cmd.Flags(), clirpc.Client().SetAppNetworkInterface(args[0], netifc))
internal.PrintOutput(cmd.Flags(), "OK", "OK\n")
},
}

var appLogsSinceCmd = &cobra.Command{
Use: "log <name> <timestamp>",
Short: "Logs from app since RFC3339Nano-formatted timestamp.\n \"beginning\" is a special timestamp to fetch all the logs",
Short: "Logs from app since RFC3339Nano-formatted timestamp.\n\"beginning\" is a special timestamp to fetch all the logs",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var t time.Time
Expand Down
6 changes: 3 additions & 3 deletions pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (v *Visor) SetAppNetworkInterface(appName, netifc string) error {
return fmt.Errorf("app %s is not allowed to set network interface", appName)
}

v.log.Infof("Changing %s network interface to %q", appName, netifc)
v.log.Infof("Changing %s network interface to %v", appName, netifc)

const (
netifcArgName = "--netifc"
Expand All @@ -511,7 +511,7 @@ func (v *Visor) SetAppKillswitch(appName string, killswitch bool) error {
return fmt.Errorf("app %s is not allowed to set killswitch", appName)
}

v.log.Infof("Setting %s killswitch to %q", appName, killswitch)
v.log.Infof("Setting %s killswitch to %v", appName, killswitch)

const (
killSwitchArg = "--killswitch"
Expand All @@ -532,7 +532,7 @@ func (v *Visor) SetAppSecure(appName string, isSecure bool) error {
return fmt.Errorf("app %s is not allowed to change 'secure' parameter", appName)
}

v.log.Infof("Setting %s secure to %q", appName, isSecure)
v.log.Infof("Setting %s secure to %v", appName, isSecure)

const (
secureArgName = "--secure"
Expand Down

0 comments on commit a3e4954

Please sign in to comment.