Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skywire-cli terminal user interface improvements #1390

Merged
merged 17 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 1.2.0

### Added
- `skywire-cil visor hv` subcommand [#1390](https://github.com/skycoin/skywire/pull/1390)
- info field to Service struct [#1382](https://github.com/skycoin/skywire/pull/1382)
- `skywire-cli` subcommand `arg` under `visor app` [#1356](https://github.com/skycoin/skywire/pull/1356)
- `log_store` field to `transport` in config [#1386](https://github.com/skycoin/skywire/pull/1386)
- `type`, `location`, `rotation_interval`, field to `log_store` inside `transport` in config [#1374](https://github.com/skycoin/skywire/pull/1374)
- transport file logging to CSV [#1374](https://github.com/skycoin/skywire/pull/1374)
- transport file logging to CSV [#1374](https://github.com/skycoin/skywire/pull/1374)
- `skywire-cli config priv` & `skywire-cli visor priv` subcommands and rpc [#1369](https://github.com/skycoin/skywire/issues/1369)
- dmsghttp server [#1364](https://github.com/skycoin/skywire/issues/1364)

### Changed
- moved `skywire-cli visor` subcommands into `skywire-cil visor hv` [#1390](https://github.com/skycoin/skywire/pull/1390)
- use flags for `skywire-cli visor route` & `skywire-cli visor tp` [#1390](https://github.com/skycoin/skywire/pull/1390)
- moved `skywire-cli` subcommand `autoconnect` from `visor app` to `visor app arg` [#1356](https://github.com/skycoin/skywire/pull/1356)

### Removed
### Fixed
- negative waitgroup [#1372](https://github.com/skycoin/skywire/pull/1372)
- absence of git in makefile [#1368](https://github.com/skycoin/skywire/pull/1368)
- rpc error in cli for json [#1367](https://github.com/skycoin/skywire/pull/1367)
- StartVPNCient logic [#1366](https://github.com/skycoin/skywire/pull/1366)

## 1.1.0

Expand Down Expand Up @@ -54,6 +63,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `skywire-cli visor tp add` flag `--public` [#1346](https://github.com/skycoin/skywire/pull/1346)
- remove updater settings from UI

### Fixed
- UI update button [#1349](https://github.com/skycoin/skywire/pull/1349)

## 1.0.0

### Added
Expand Down
14 changes: 6 additions & 8 deletions cmd/skywire-cli/commands/mdisc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ var masterLogger = logging.NewMasterLogger()
var packageLogger = masterLogger.PackageLogger("mdisc:disc")

func init() {
RootCmd.PersistentFlags().StringVar(&mdAddr, "addr", utilenv.DmsgDiscAddr, "address of DMSG discovery server\n")
RootCmd.AddCommand(
entryCmd,
availableServersCmd,
)
entryCmd.PersistentFlags().StringVar(&mdAddr, "addr", utilenv.DmsgDiscAddr, "address of DMSG discovery server\n")
availableServersCmd.PersistentFlags().StringVar(&mdAddr, "addr", utilenv.DmsgDiscAddr, "address of DMSG discovery server\n")
var helpflag bool
RootCmd.Flags().BoolVarP(&helpflag, "help", "h", false, "help for "+RootCmd.Use)
RootCmd.Flags().MarkHidden("help") //nolint
Expand All @@ -37,13 +42,6 @@ var RootCmd = &cobra.Command{
Short: "Query remote DMSG Discovery",
}

func init() {
RootCmd.AddCommand(
entryCmd,
availableServersCmd,
)
}

var entryCmd = &cobra.Command{
Use: "entry <visor-public-key>",
Short: "Fetch an entry",
Expand Down
28 changes: 18 additions & 10 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
cliconfig "github.com/skycoin/skywire/cmd/skywire-cli/commands/config"
clidmsgpty "github.com/skycoin/skywire/cmd/skywire-cli/commands/dmsgpty"
climdisc "github.com/skycoin/skywire/cmd/skywire-cli/commands/mdisc"
clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
clirtfind "github.com/skycoin/skywire/cmd/skywire-cli/commands/rtfind"
clivisor "github.com/skycoin/skywire/cmd/skywire-cli/commands/visor"
clivpn "github.com/skycoin/skywire/cmd/skywire-cli/commands/vpn"
Expand All @@ -26,10 +25,11 @@ var rootCmd = &cobra.Command{
┌─┐┬┌─┬ ┬┬ ┬┬┬─┐┌─┐ ┌─┐┬ ┬
└─┐├┴┐└┬┘││││├┬┘├┤───│ │ │
└─┘┴ ┴ ┴ └┴┘┴┴└─└─┘ └─┘┴─┘┴`,
SilenceErrors: true,
SilenceUsage: true,
DisableSuggestions: true,
Version: buildinfo.Version(),
SilenceErrors: true,
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
}

func init() {
Expand All @@ -42,12 +42,11 @@ func init() {
climdisc.RootCmd,
clicompletion.RootCmd,
)

var helpflag bool
var jsonOutput bool

rootCmd.PersistentFlags().StringVar(&clirpc.Addr, "rpc", "localhost:3435", "RPC server address")
rootCmd.PersistentFlags().BoolVar(&jsonOutput, internal.JSONString, false, "print output in json")
rootCmd.PersistentFlags().MarkHidden(internal.JSONString) //nolint
var helpflag bool
rootCmd.SetUsageTemplate(help)
rootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for "+rootCmd.Use)
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
rootCmd.PersistentFlags().MarkHidden("help") //nolint
Expand All @@ -68,8 +67,17 @@ func Execute() {
NoExtraNewlines: true,
NoBottomNewline: true,
})

if err := rootCmd.Execute(); err != nil {
log.Fatal("Failed to execute command: ", err)
}
}

const help = "Usage:\r\n" +
" {{.UseLine}}{{if .HasAvailableSubCommands}}{{end}} {{if gt (len .Aliases) 0}}\r\n\r\n" +
"{{.NameAndAliases}}{{end}}{{if .HasAvailableSubCommands}}\r\n\r\n" +
"Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand)}}\r\n " +
"{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\r\n\r\n" +
"Flags:\r\n" +
"{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\r\n\r\n" +
"Global Flags:\r\n" +
"{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}\r\n\r\n"
3 changes: 2 additions & 1 deletion cmd/skywire-cli/commands/rtfind/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ var frMinHops, frMaxHops uint16
var timeout time.Duration

func init() {
RootCmd.Flags().StringVarP(&frAddr, "addr", "a", utilenv.RouteFinderAddr, "route finder service address")
RootCmd.Flags().SortFlags = false
RootCmd.Flags().Uint16VarP(&frMinHops, "min-hops", "n", 1, "minimum hops")
RootCmd.Flags().Uint16VarP(&frMaxHops, "max-hops", "x", 1000, "maximum hops")
RootCmd.Flags().DurationVarP(&timeout, "timeout", "t", 10*time.Second, "request timeout")
RootCmd.Flags().StringVarP(&frAddr, "addr", "a", utilenv.RouteFinderAddr, "route finder service address\n")
var helpflag bool
RootCmd.Flags().BoolVarP(&helpflag, "help", "h", false, "help for "+RootCmd.Use)
RootCmd.Flags().MarkHidden("help") //nolint
Expand Down
15 changes: 12 additions & 3 deletions cmd/skywire-cli/commands/visor/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ var argCmd = &cobra.Command{
var appCmd = &cobra.Command{
Use: "app",
Short: "App settings",
Long: "\n App settings",
}

var lsAppsCmd = &cobra.Command{
Use: "ls",
Short: "List apps",
Long: "\n List apps",
Run: func(cmd *cobra.Command, _ []string) {
states, err := clirpc.Client(cmd.Flags()).Apps()
internal.Catch(cmd.Flags(), err)
Expand Down Expand Up @@ -92,6 +94,7 @@ var lsAppsCmd = &cobra.Command{
var startAppCmd = &cobra.Command{
Use: "start <name>",
Short: "Launch app",
Long: "\n Launch app",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
internal.Catch(cmd.Flags(), clirpc.Client(cmd.Flags()).StartApp(args[0]))
Expand All @@ -102,6 +105,7 @@ var startAppCmd = &cobra.Command{
var stopAppCmd = &cobra.Command{
Use: "stop <name>",
Short: "Halt app",
Long: "\n Halt app",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
internal.Catch(cmd.Flags(), clirpc.Client(cmd.Flags()).StopApp(args[0]))
Expand Down Expand Up @@ -131,6 +135,7 @@ var setAppAutostartCmd = &cobra.Command{
var setAppKillswitchCmd = &cobra.Command{
Use: "killswitch <name> (true|false)",
Short: "Set app killswitch",
Long: "\n Set app killswitch",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var killswitch bool
Expand All @@ -150,6 +155,7 @@ var setAppKillswitchCmd = &cobra.Command{
var setAppSecureCmd = &cobra.Command{
Use: "secure <name> (true|false)",
Short: "Set app secure",
Long: "\n Set app secure",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var secure bool
Expand All @@ -168,7 +174,8 @@ var setAppSecureCmd = &cobra.Command{

var setAppPasscodeCmd = &cobra.Command{
Use: "passcode <name> <passcode>",
Short: "Set app passcode.\n \"remove\" is a special arg to remove the passcode",
Short: "Set app passcode",
Long: "\n Set app passcode.\n\r\n\r \"remove\" is a special arg to remove the passcode",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
passcode := args[1]
Expand All @@ -182,7 +189,8 @@ var setAppPasscodeCmd = &cobra.Command{

var setAppNetworkInterfaceCmd = &cobra.Command{
Use: "netifc <name> <interface>",
Short: "Set app network interface.\n \"remove\" is a special arg to remove the netifc",
Short: "Set app network interface",
Long: "Set app network interface.\n\r\n\r \"remove\" is a special arg to remove the netifc",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
netifc := args[1]
Expand All @@ -196,7 +204,8 @@ var setAppNetworkInterfaceCmd = &cobra.Command{

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",
Long: "\n Logs from app since RFC3339Nano-formatted timestamp.\n\r\n\r \"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
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/visor/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func init() {
var execCmd = &cobra.Command{
Use: "exec <command>",
Short: "Execute a command",
Long: "\n Execute a command",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
out, err := clirpc.Client(cmd.Flags()).Exec(strings.Join(args, " "))
Expand Down
85 changes: 85 additions & 0 deletions cmd/skywire-cli/commands/visor/hv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package clivisor

import (
"fmt"

"github.com/spf13/cobra"
"github.com/toqueteos/webbrowser"

"github.com/skycoin/skywire-utilities/pkg/cipher"
clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/visor/visorconfig"
)

func init() {
RootCmd.AddCommand(hvCmd)
hvCmd.AddCommand(hvuiCmd)
hvCmd.AddCommand(hvpkCmd)
hvpkCmd.Flags().StringVarP(&path, "input", "i", "", "path of input config file.")
hvpkCmd.Flags().BoolVarP(&pkg, "pkg", "p", false, "read from /opt/skywire/skywire.json")
hvpkCmd.Flags().BoolVarP(&web, "http", "w", false, "serve public key via http")
hvCmd.AddCommand(chvpkCmd)

}

var hvCmd = &cobra.Command{
Use: "hv",
Short: "Hypervisor",
Long: "\n Hypervisor\n\r\n\r Access the hypervisor UI\n\r View remote hypervisor public key",
}

var hvuiCmd = &cobra.Command{
Use: "ui",
Short: "open Hypervisor UI in default browser",
Long: "\n open Hypervisor UI in default browser",
Run: func(_ *cobra.Command, _ []string) {
//TODO: get the actual port from config instead of using default value here
if err := webbrowser.Open("http://127.0.0.1:8000/"); err != nil {
logger.Fatal("Failed to open hypervisor UI in browser:", err)
}
},
}

var hvpkCmd = &cobra.Command{
Use: "cpk",
Short: "Public key of remote hypervisor(s) set in config",
Long: "\n Public key of remote hypervisor(s) set in config",
Run: func(cmd *cobra.Command, _ []string) {
var hypervisors []cipher.PubKey

if pkg {
path = visorconfig.Pkgpath
}

if path != "" {
conf, err := visorconfig.ReadFile(path)
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Failed to read config: %v", err))
}
hypervisors = conf.Hypervisors
} else {
client := clirpc.Client(cmd.Flags())
overview, err := client.Overview()
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Failed to connect: %v", err))
}
hypervisors = overview.Hypervisors
}
internal.PrintOutput(cmd.Flags(), hypervisors, fmt.Sprintf("%v\n", hypervisors))
},
}

var chvpkCmd = &cobra.Command{
Use: "pk",
Short: "Public key of remote hypervisor(s)",
Long: "Public key of remote hypervisor(s) which are currently connected to",
Run: func(cmd *cobra.Command, _ []string) {
client := clirpc.Client(cmd.Flags())
overview, err := client.Overview()
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Failed to connect: %v", err))
}
internal.PrintOutput(cmd.Flags(), overview.ConnectedHypervisor, fmt.Sprintf("%v\n", overview.ConnectedHypervisor))
},
}
21 changes: 0 additions & 21 deletions cmd/skywire-cli/commands/visor/hvui.go

This file was deleted.

Loading