From e2b85b1b47338d69c9fb02e8e959235c3845f415 Mon Sep 17 00:00:00 2001 From: Moses Narrow <36607567+0pcom@users.noreply.github.com> Date: Tue, 27 Feb 2024 08:18:13 -0600 Subject: [PATCH] minor cli interface refactor (#53) * move coloredcobra initialization to command wrapper * fix ci errors * update dmsg to latest commit on develop --- cmd/address-resolver/address-resolver.go | 33 +++++++++++ cmd/address-resolver/commands/root.go | 29 ---------- cmd/config-bootstrapper/commands/root.go | 29 ---------- cmd/config-bootstrapper/config.go | 33 +++++++++++ cmd/dmsg-monitor/commands/root.go | 28 --------- cmd/dmsg-monitor/dmsg-monitor.go | 37 +++++++++++- cmd/keys-gen/commands/root.go | 32 ----------- cmd/keys-gen/keys-gen.go | 33 +++++++++++ cmd/liveness-checker/commands/root.go | 29 ---------- cmd/liveness-checker/liveness-checker.go | 37 +++++++++++- cmd/network-monitor/commands/root.go | 29 ---------- cmd/network-monitor/network-monitor.go | 37 +++++++++++- cmd/node-visualizer/commands/root.go | 29 ---------- cmd/node-visualizer/node-visualizer.go | 37 +++++++++++- cmd/public-visor-monitor/commands/root.go | 29 ---------- .../public-visor-monitor.go | 37 +++++++++++- cmd/route-finder/commands/root.go | 29 ---------- cmd/route-finder/route-finder.go | 33 +++++++++++ cmd/setup-node/setup-node.go | 36 +++++++++++- .../skysocks-lite-client.go | 3 +- cmd/skysocks-monitor/commands/root.go | 29 ---------- cmd/skysocks-monitor/skysocks-monitor.go | 37 +++++++++++- cmd/skywire-services/services.go | 1 - cmd/sw-env/commands/root.go | 29 ---------- cmd/sw-env/sw-env.go | 37 +++++++++++- cmd/tpd-monitor/commands/root.go | 28 --------- cmd/tpd-monitor/tpd-monitor.go | 37 +++++++++++- cmd/transport-discovery/commands/root.go | 29 ---------- .../transport-discovery.go | 37 +++++++++++- cmd/transport-setup/commands/root.go | 36 +----------- cmd/transport-setup/transport-setup.go | 37 +++++++++++- cmd/visor-map/commands/root.go | 29 ---------- cmd/vpn-monitor/commands/root.go | 30 ---------- cmd/vpn-monitor/vpn-monitor.go | 37 +++++++++++- go.mod | 3 +- go.sum | 10 ++-- vendor/github.com/go-chi/chi/v5/CHANGELOG.md | 9 ++- vendor/github.com/go-chi/chi/v5/README.md | 2 +- vendor/github.com/go-chi/chi/v5/SECURITY.md | 5 ++ vendor/github.com/go-chi/chi/v5/context.go | 23 ++++---- .../go-chi/chi/v5/middleware/compress.go | 39 ++++++------- .../go-chi/chi/v5/middleware/logger.go | 9 +-- .../go-chi/chi/v5/middleware/nocache.go | 9 +-- .../go-chi/chi/v5/middleware/profiler.go | 32 +++-------- .../go-chi/chi/v5/middleware/recoverer.go | 13 ++--- .../go-chi/chi/v5/middleware/route_headers.go | 57 ++++++++----------- .../go-chi/chi/v5/middleware/sunset.go | 25 ++++++++ .../chi/v5/middleware/supress_notfound.go | 27 +++++++++ .../go-chi/chi/v5/middleware/timeout.go | 23 ++++---- .../go-chi/chi/v5/middleware/url_format.go | 37 ++++++------ vendor/github.com/go-chi/chi/v5/mux.go | 9 ++- .../github.com/skycoin/dmsg/pkg/disc/entry.go | 6 ++ .../skycoin/dmsg/pkg/dmsg/client.go | 38 ++++++++++--- .../github.com/skycoin/dmsg/pkg/dmsg/const.go | 4 ++ .../skycoin/dmsg/pkg/dmsg/entity_common.go | 15 +++-- .../skycoin/dmsg/pkg/dmsg/server.go | 12 ++-- vendor/modules.txt | 5 +- 57 files changed, 811 insertions(+), 653 deletions(-) create mode 100644 vendor/github.com/go-chi/chi/v5/SECURITY.md create mode 100644 vendor/github.com/go-chi/chi/v5/middleware/sunset.go create mode 100644 vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go diff --git a/cmd/address-resolver/address-resolver.go b/cmd/address-resolver/address-resolver.go index a1197239..6136cdde 100644 --- a/cmd/address-resolver/address-resolver.go +++ b/cmd/address-resolver/address-resolver.go @@ -2,9 +2,42 @@ package main import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + "github.com/skycoin/skywire-services/cmd/address-resolver/commands" ) +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} + func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/address-resolver/commands/root.go b/cmd/address-resolver/commands/root.go index 386f5cc4..37f0056c 100644 --- a/cmd/address-resolver/commands/root.go +++ b/cmd/address-resolver/commands/root.go @@ -10,7 +10,6 @@ import ( "strings" "time" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/dmsg/pkg/direct" "github.com/skycoin/dmsg/pkg/dmsg" @@ -67,11 +66,6 @@ func init() { RootCmd.Flags().BoolVar(&testEnvironment, "test-environment", false, "distinguished between prod and test environment\033[0m") RootCmd.Flags().Var(&sk, "sk", "dmsg secret key\r") RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for address-resolver") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -233,31 +227,8 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/config-bootstrapper/commands/root.go b/cmd/config-bootstrapper/commands/root.go index de1bcbdb..3f78c220 100644 --- a/cmd/config-bootstrapper/commands/root.go +++ b/cmd/config-bootstrapper/commands/root.go @@ -9,7 +9,6 @@ import ( "log" "os" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/dmsg/pkg/direct" "github.com/skycoin/dmsg/pkg/dmsg" "github.com/skycoin/dmsg/pkg/dmsghttp" @@ -18,7 +17,6 @@ import ( "github.com/skycoin/skywire-utilities/pkg/cmdutil" "github.com/skycoin/skywire-utilities/pkg/logging" "github.com/skycoin/skywire-utilities/pkg/tcpproxy" - "github.com/spf13/cobra" "github.com/skycoin/skywire-services/pkg/config-bootstrapper/api" @@ -42,11 +40,6 @@ func init() { RootCmd.Flags().StringVar(&dmsgDisc, "dmsg-disc", "http://dmsgd.skywire.skycoin.com", "url of dmsg-discovery\033[0m") RootCmd.Flags().Var(&sk, "sk", "dmsg secret key\r") RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for config-bootstrapper") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -161,29 +154,7 @@ func readConfig(log *logging.Logger, confPath string) (config api.Config) { // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/config-bootstrapper/config.go b/cmd/config-bootstrapper/config.go index 2f36b379..f0272485 100644 --- a/cmd/config-bootstrapper/config.go +++ b/cmd/config-bootstrapper/config.go @@ -2,9 +2,42 @@ package main import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + "github.com/skycoin/skywire-services/cmd/config-bootstrapper/commands" ) +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} + func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/dmsg-monitor/commands/root.go b/cmd/dmsg-monitor/commands/root.go index 7f091d86..ae00e5e1 100644 --- a/cmd/dmsg-monitor/commands/root.go +++ b/cmd/dmsg-monitor/commands/root.go @@ -8,7 +8,6 @@ import ( "os" "time" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" @@ -42,11 +41,6 @@ func init() { RootCmd.Flags().StringVar(&tag, "tag", "dmsg_monitor", "logging tag\033[0m") RootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m") RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsg-monitor") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -128,29 +122,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/dmsg-monitor/dmsg-monitor.go b/cmd/dmsg-monitor/dmsg-monitor.go index 50b82315..a582269c 100644 --- a/cmd/dmsg-monitor/dmsg-monitor.go +++ b/cmd/dmsg-monitor/dmsg-monitor.go @@ -1,8 +1,43 @@ // Package main cmd/dmsg-monitor/dmsg-monitor.go package main -import "github.com/skycoin/skywire-services/cmd/dmsg-monitor/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/dmsg-monitor/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/keys-gen/commands/root.go b/cmd/keys-gen/commands/root.go index 84c54c77..abe107b3 100644 --- a/cmd/keys-gen/commands/root.go +++ b/cmd/keys-gen/commands/root.go @@ -5,20 +5,11 @@ import ( "fmt" "log" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/spf13/cobra" ) -func init() { - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for keys-gen") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint -} - // RootCmd contains the root command var RootCmd = &cobra.Command{ Use: "kg", @@ -41,30 +32,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/keys-gen/keys-gen.go b/cmd/keys-gen/keys-gen.go index ce84ce7e..849353c6 100644 --- a/cmd/keys-gen/keys-gen.go +++ b/cmd/keys-gen/keys-gen.go @@ -2,9 +2,42 @@ package main import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + "github.com/skycoin/skywire-services/cmd/keys-gen/commands" ) +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} + func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/liveness-checker/commands/root.go b/cmd/liveness-checker/commands/root.go index 9e3f9c99..12ef4f33 100644 --- a/cmd/liveness-checker/commands/root.go +++ b/cmd/liveness-checker/commands/root.go @@ -8,7 +8,6 @@ import ( "os" "strings" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cmdutil" @@ -43,11 +42,6 @@ func init() { RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic") RootCmd.Flags().StringVar(&redisURL, "redis", "redis://localhost:6379", "connections string for a redis store\033[0m") RootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for liveness-checker") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -131,30 +125,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/liveness-checker/liveness-checker.go b/cmd/liveness-checker/liveness-checker.go index 1a956b8a..8339ea9d 100644 --- a/cmd/liveness-checker/liveness-checker.go +++ b/cmd/liveness-checker/liveness-checker.go @@ -1,8 +1,43 @@ // Package main cmd/liveness-checker/liveness-checker.go package main -import "github.com/skycoin/skywire-services/cmd/liveness-checker/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/liveness-checker/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/network-monitor/commands/root.go b/cmd/network-monitor/commands/root.go index a9e176e8..24ae39d0 100644 --- a/cmd/network-monitor/commands/root.go +++ b/cmd/network-monitor/commands/root.go @@ -9,7 +9,6 @@ import ( "strings" "time" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" @@ -61,11 +60,6 @@ func init() { RootCmd.Flags().StringVar(&redisURL, "redis", "redis://localhost:6379", "connections string for a redis store\033[0m") RootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m") RootCmd.Flags().IntVar(&redisPoolSize, "redis-pool-size", 10, "redis connection pool size\033[0m") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for network-monitor") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -182,30 +176,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/network-monitor/network-monitor.go b/cmd/network-monitor/network-monitor.go index a8e1b945..02b1aea1 100644 --- a/cmd/network-monitor/network-monitor.go +++ b/cmd/network-monitor/network-monitor.go @@ -1,8 +1,43 @@ // Package main cmd/network-monitor/network-monitor.go package main -import "github.com/skycoin/skywire-services/cmd/network-monitor/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/network-monitor/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/node-visualizer/commands/root.go b/cmd/node-visualizer/commands/root.go index 0578539d..7ea196e4 100644 --- a/cmd/node-visualizer/commands/root.go +++ b/cmd/node-visualizer/commands/root.go @@ -9,7 +9,6 @@ import ( "os" "time" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cmdutil" @@ -37,11 +36,6 @@ func init() { RootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m") RootCmd.Flags().StringVar(&tag, "tag", "node-visualizer", "logging tag\033[0m") RootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis\033[0m") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for node-visualizer") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -106,30 +100,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/node-visualizer/node-visualizer.go b/cmd/node-visualizer/node-visualizer.go index 0c20e752..18cb69c8 100644 --- a/cmd/node-visualizer/node-visualizer.go +++ b/cmd/node-visualizer/node-visualizer.go @@ -1,8 +1,43 @@ // Package main cmd/node-visualizer/node-visualizer.go package main -import "github.com/skycoin/skywire-services/cmd/node-visualizer/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/node-visualizer/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/public-visor-monitor/commands/root.go b/cmd/public-visor-monitor/commands/root.go index 83436768..0c04d028 100644 --- a/cmd/public-visor-monitor/commands/root.go +++ b/cmd/public-visor-monitor/commands/root.go @@ -7,7 +7,6 @@ import ( "os" "time" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire-utilities/pkg/cmdutil" @@ -32,11 +31,6 @@ func init() { RootCmd.Flags().StringVarP(&confPath, "config", "c", "public-visor-monitor.json", "config file location.\033[0m") RootCmd.Flags().StringVar(&tag, "tag", "public_visor_monitor", "logging tag\033[0m") RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for ") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -109,30 +103,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/public-visor-monitor/public-visor-monitor.go b/cmd/public-visor-monitor/public-visor-monitor.go index 6be96459..ef9255e0 100644 --- a/cmd/public-visor-monitor/public-visor-monitor.go +++ b/cmd/public-visor-monitor/public-visor-monitor.go @@ -1,8 +1,43 @@ // Package main cmd/public-visor-monitor/public-visor-monitor.go package main -import "github.com/skycoin/skywire-services/cmd/public-visor-monitor/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/public-visor-monitor/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/route-finder/commands/root.go b/cmd/route-finder/commands/root.go index 9d0b9545..de8731eb 100644 --- a/cmd/route-finder/commands/root.go +++ b/cmd/route-finder/commands/root.go @@ -9,7 +9,6 @@ import ( "os" "time" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/dmsg/pkg/direct" "github.com/skycoin/dmsg/pkg/dmsg" @@ -55,11 +54,6 @@ func init() { RootCmd.Flags().StringVar(&dmsgDisc, "dmsg-disc", "http://dmsgd.skywire.skycoin.com", "url of dmsg-discovery\033[0m") RootCmd.Flags().Var(&sk, "sk", "dmsg secret key\r") RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for route-finder") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -192,30 +186,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/route-finder/route-finder.go b/cmd/route-finder/route-finder.go index 8effbfbe..083b5c57 100644 --- a/cmd/route-finder/route-finder.go +++ b/cmd/route-finder/route-finder.go @@ -2,9 +2,42 @@ package main import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + "github.com/skycoin/skywire-services/cmd/route-finder/commands" ) +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} + func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/setup-node/setup-node.go b/cmd/setup-node/setup-node.go index 12a823d6..a6d88af6 100644 --- a/cmd/setup-node/setup-node.go +++ b/cmd/setup-node/setup-node.go @@ -1,8 +1,42 @@ // Package main cmd/setup-node/setup-node.go package main -import "github.com/skycoin/skywire/cmd/setup-node/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/skycoin/skywire/cmd/setup-node/commands" + "github.com/spf13/cobra" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/skysocks-lite-client/skysocks-lite-client.go b/cmd/skysocks-lite-client/skysocks-lite-client.go index 8cbcb55d..6b044503 100644 --- a/cmd/skysocks-lite-client/skysocks-lite-client.go +++ b/cmd/skysocks-lite-client/skysocks-lite-client.go @@ -11,7 +11,6 @@ import ( "os" "time" - "github.com/skycoin/skywire-services/internal/skysocks" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire-utilities/pkg/netutil" @@ -20,6 +19,8 @@ import ( "github.com/skycoin/skywire/pkg/app/appserver" "github.com/skycoin/skywire/pkg/routing" "github.com/skycoin/skywire/pkg/visor/visorconfig" + + "github.com/skycoin/skywire-services/internal/skysocks" ) const ( diff --git a/cmd/skysocks-monitor/commands/root.go b/cmd/skysocks-monitor/commands/root.go index 009bff0d..17a11000 100644 --- a/cmd/skysocks-monitor/commands/root.go +++ b/cmd/skysocks-monitor/commands/root.go @@ -7,7 +7,6 @@ import ( "os" "time" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire-utilities/pkg/cmdutil" @@ -30,11 +29,6 @@ func init() { RootCmd.Flags().DurationVarP(&sleepDeregistration, "sleep-deregistration", "s", 10, "Sleep time for derigstration process in minutes\033[0m") RootCmd.Flags().StringVarP(&confPath, "config", "c", "skysocks-monitor.json", "config file location.\033[0m") RootCmd.Flags().StringVar(&tag, "tag", "skysocks_monitor", "logging tag\033[0m") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for skysocks-monitor") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -99,30 +93,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/skysocks-monitor/skysocks-monitor.go b/cmd/skysocks-monitor/skysocks-monitor.go index a5d92ba7..0f80d5d2 100644 --- a/cmd/skysocks-monitor/skysocks-monitor.go +++ b/cmd/skysocks-monitor/skysocks-monitor.go @@ -1,8 +1,43 @@ // Package main cmd/skysocks-monitor/skysocks-monitor.go package main -import "github.com/skycoin/skywire-services/cmd/skysocks-monitor/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/skysocks-monitor/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/skywire-services/services.go b/cmd/skywire-services/services.go index dc0f15d1..a9d73f7a 100644 --- a/cmd/skywire-services/services.go +++ b/cmd/skywire-services/services.go @@ -75,7 +75,6 @@ func main() { NoExtraNewlines: true, NoBottomNewline: true, }) - if err := RootCmd.Execute(); err != nil { fmt.Println(err) } diff --git a/cmd/sw-env/commands/root.go b/cmd/sw-env/commands/root.go index 60bd0fdc..f5688e9a 100644 --- a/cmd/sw-env/commands/root.go +++ b/cmd/sw-env/commands/root.go @@ -5,7 +5,6 @@ import ( "fmt" "log" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/spf13/cobra" @@ -54,11 +53,6 @@ func init() { RootCmd.Flags().BoolVarP(&localFlag, "local", "l", false, "Environment with skywire-services on localhost\033[0m") RootCmd.Flags().BoolVarP(&dockerFlag, "docker", "d", false, "Environment with dockerized skywire-services\033[0m") RootCmd.Flags().StringVarP(&dockerNetwork, "network", "n", "SKYNET", "Docker network to use\033[0m") - 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 } var visorCmd = &cobra.Command{ @@ -87,30 +81,7 @@ var setupCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/sw-env/sw-env.go b/cmd/sw-env/sw-env.go index 0752fb81..9938cb4b 100644 --- a/cmd/sw-env/sw-env.go +++ b/cmd/sw-env/sw-env.go @@ -1,8 +1,43 @@ // Package main cmd/sw-env/sw-env.go package main -import "github.com/skycoin/skywire-services/cmd/sw-env/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/sw-env/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/tpd-monitor/commands/root.go b/cmd/tpd-monitor/commands/root.go index f88273b9..383663f7 100644 --- a/cmd/tpd-monitor/commands/root.go +++ b/cmd/tpd-monitor/commands/root.go @@ -8,7 +8,6 @@ import ( "os" "time" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" @@ -42,11 +41,6 @@ func init() { RootCmd.Flags().StringVar(&arURL, "ar-url", "", "url to address resolver.\033[0m") RootCmd.Flags().StringVar(&tag, "tag", "tpd-monitor", "logging tag\033[0m") RootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514\033[0m") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for tpd-monitor") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -132,29 +126,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/tpd-monitor/tpd-monitor.go b/cmd/tpd-monitor/tpd-monitor.go index d6f882dc..68e9a61c 100644 --- a/cmd/tpd-monitor/tpd-monitor.go +++ b/cmd/tpd-monitor/tpd-monitor.go @@ -1,8 +1,43 @@ // Package main cmd/tpd-monitor/tpd-monitor.go package main -import "github.com/skycoin/skywire-services/cmd/tpd-monitor/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/tpd-monitor/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/transport-discovery/commands/root.go b/cmd/transport-discovery/commands/root.go index 1aeea99e..488063ec 100644 --- a/cmd/transport-discovery/commands/root.go +++ b/cmd/transport-discovery/commands/root.go @@ -10,7 +10,6 @@ import ( "strings" "time" - cc "github.com/ivanpirog/coloredcobra" logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/skycoin/dmsg/pkg/direct" "github.com/skycoin/dmsg/pkg/dmsg" @@ -72,11 +71,6 @@ func init() { RootCmd.Flags().BoolVar(&testEnvironment, "test-environment", false, "distinguished between prod and test environment\033[0m") RootCmd.Flags().Var(&sk, "sk", "dmsg secret key\r") RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for transport-discovery") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -247,30 +241,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/transport-discovery/transport-discovery.go b/cmd/transport-discovery/transport-discovery.go index 823c3242..4a3ced81 100644 --- a/cmd/transport-discovery/transport-discovery.go +++ b/cmd/transport-discovery/transport-discovery.go @@ -1,8 +1,43 @@ // Package main cmd/transport-discovery/transport-discovery.go package main -import "github.com/skycoin/skywire-services/cmd/transport-discovery/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/transport-discovery/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/transport-setup/commands/root.go b/cmd/transport-setup/commands/root.go index c983941f..5988116b 100644 --- a/cmd/transport-setup/commands/root.go +++ b/cmd/transport-setup/commands/root.go @@ -7,7 +7,6 @@ import ( "net/http" "time" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/logging" "github.com/spf13/cobra" @@ -24,15 +23,6 @@ var ( func init() { RootCmd.Flags().StringVarP(&configFile, "config", "c", "", "path to config file\033[0m") RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "info", "set log level one of: info, error, warn, debug, trace, panic") - err := RootCmd.MarkFlagRequired("config") - if err != nil { - log.Fatal("config flag is not specified") - } - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for transport-setup") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -49,6 +39,9 @@ var RootCmd = &cobra.Command{ DisableFlagsInUseLine: true, Version: buildinfo.Version(), Run: func(_ *cobra.Command, args []string) { + if configFile == "" { + log.Fatal("please specify config file") + } const loggerTag = "transport_setup" log := logging.MustGetLogger(loggerTag) lvl, err := logging.LevelFromString(logLvl) @@ -73,30 +66,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/transport-setup/transport-setup.go b/cmd/transport-setup/transport-setup.go index 02decbc6..d2027e5e 100644 --- a/cmd/transport-setup/transport-setup.go +++ b/cmd/transport-setup/transport-setup.go @@ -1,8 +1,43 @@ // Package main cmd/transport-setup/transport-setup.go package main -import "github.com/skycoin/skywire-services/cmd/transport-setup/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/transport-setup/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/cmd/visor-map/commands/root.go b/cmd/visor-map/commands/root.go index 7b7e4ba2..ebac95c6 100644 --- a/cmd/visor-map/commands/root.go +++ b/cmd/visor-map/commands/root.go @@ -14,7 +14,6 @@ import ( sm "github.com/flopp/go-staticmaps" "github.com/golang/geo/s2" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/logging" "github.com/spf13/cobra" @@ -49,11 +48,6 @@ func init() { RootCmd.Flags().IntVar(&height, "height", 800, "image height\033[0m") RootCmd.Flags().StringVarP(&output, "output", "o", "./map"+imageExtension, "output .jpg file\033[0m") RootCmd.Flags().StringVar(&trackerURL, "tracker-url", defaultUptimeTrackerHost, "uptime tracker URL\033[0m") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for visor-map") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -142,19 +136,6 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - NoExtraNewlines: true, - NoBottomNewline: true, - }) if err := RootCmd.Execute(); err != nil { log.Fatal("Failed to execute command: ", err) } @@ -168,13 +149,3 @@ type VisorDef struct { Lat float64 `json:"lat"` Lon float64 `json:"lon"` } - -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" diff --git a/cmd/vpn-monitor/commands/root.go b/cmd/vpn-monitor/commands/root.go index c4722c70..4af2d45a 100644 --- a/cmd/vpn-monitor/commands/root.go +++ b/cmd/vpn-monitor/commands/root.go @@ -7,13 +7,11 @@ import ( "os" "time" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/skywire-utilities/pkg/buildinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire-utilities/pkg/cmdutil" "github.com/skycoin/skywire-utilities/pkg/logging" "github.com/skycoin/skywire-utilities/pkg/tcpproxy" - "github.com/spf13/cobra" "github.com/skycoin/skywire-services/pkg/vpn-monitor/api" @@ -31,11 +29,6 @@ func init() { RootCmd.Flags().DurationVarP(&sleepDeregistration, "sleep-deregistration", "s", 10, "Sleep time for derigstration process in minutes\033[0m") RootCmd.Flags().StringVarP(&confPath, "config", "c", "vpn-monitor.json", "config file location.\033[0m") RootCmd.Flags().StringVar(&tag, "tag", "vpn_monitor", "logging tag\033[0m") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for vpn-monitor") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root command @@ -100,30 +93,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - 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" diff --git a/cmd/vpn-monitor/vpn-monitor.go b/cmd/vpn-monitor/vpn-monitor.go index 69413391..fc0043f7 100644 --- a/cmd/vpn-monitor/vpn-monitor.go +++ b/cmd/vpn-monitor/vpn-monitor.go @@ -1,8 +1,43 @@ // Package main cmd/vpn-monitor/vpn-monitor.go package main -import "github.com/skycoin/skywire-services/cmd/vpn-monitor/commands" +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/skywire-services/cmd/vpn-monitor/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgpty-cli") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) commands.Execute() } + +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" diff --git a/go.mod b/go.mod index 9eaab754..f519afe2 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/dgraph-io/badger/v3 v3.2103.2 github.com/docker/docker v1.13.1 github.com/flopp/go-staticmaps v0.0.0-20220221183018-c226716bec53 - github.com/go-chi/chi/v5 v5.0.10 + github.com/go-chi/chi/v5 v5.0.11 github.com/go-playground/validator/v10 v10.15.1 github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis/v8 v8.11.5 @@ -157,6 +157,7 @@ require ( // Uncomment it for tests with alternative branches and run `make dep` // replace github.com/skycoin/dmsg => ../dmsg +replace github.com/skycoin/dmsg => github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4 // replace github.com/skycoin/skywire => ../skywire diff --git a/go.sum b/go.sum index 9fcd5e17..2c8fe524 100644 --- a/go.sum +++ b/go.sum @@ -107,8 +107,8 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= -github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= -github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= +github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= @@ -399,16 +399,14 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/skycoin/dmsg v1.3.14 h1:UK3/XxMFoG9xEabJ25u0jJiu143BsBhVM5tXY/gl8YI= -github.com/skycoin/dmsg v1.3.14/go.mod h1:r49d63rqTsiUUj2JG9P9Sl3MkmMbO9+YuB19vGQOfHE= +github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4 h1:sWspjJ1xySLaEOV2I1IZz3vyx3Fxs5fnxegR3u0mH3k= +github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4/go.mod h1:INEDx+ECwCGQWw/Kd0QcLmSWMhbeRRcfkxj+xATQGFg= github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA= github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o= github.com/skycoin/skycoin v0.27.1 h1:HatxsRwVSPaV4qxH6290xPBmkH/HgiuAoY2qC+e8C9I= github.com/skycoin/skycoin v0.27.1/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw= github.com/skycoin/skywire v1.3.16 h1:6p6j55FreY9nolih3kC4TM1uAuyq75TCSL+swQiOxwI= github.com/skycoin/skywire v1.3.16/go.mod h1:qbefFm0bNhSEcKOXxws/4/1q3I615an0p9zHkFetyL4= -github.com/skycoin/skywire-utilities v1.3.14 h1:AzTV3oiij7b2VgpiZHJj/oy4Tojf22I+r50Riza8Xt0= -github.com/skycoin/skywire-utilities v1.3.14/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw= github.com/skycoin/skywire-utilities v1.3.18-0.20240208220612-9f31eda72f33 h1:BzhyKolEWT8cnXZJMxC0TYGCvu3wMYdI6NOpvToN+uQ= github.com/skycoin/skywire-utilities v1.3.18-0.20240208220612-9f31eda72f33/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw= github.com/skycoin/systray v1.10.0 h1:fQZJHMylpVvfmOOTLvUssfyHVDoC8Idx6Ba2BlLEuGg= diff --git a/vendor/github.com/go-chi/chi/v5/CHANGELOG.md b/vendor/github.com/go-chi/chi/v5/CHANGELOG.md index f6eb7e6e..83d5aa28 100644 --- a/vendor/github.com/go-chi/chi/v5/CHANGELOG.md +++ b/vendor/github.com/go-chi/chi/v5/CHANGELOG.md @@ -1,9 +1,14 @@ # Changelog +## v5.0.11 (2023-12-19) + +- History of changes: see https://github.com/go-chi/chi/compare/v5.0.10...v5.0.11 + + ## v5.0.10 (2023-07-13) - Fixed small edge case in tests of v5.0.9 for older Go versions -- History of changes: see https://github.com/go-chi/chi/compare/v5.0.8...v5.0.10 +- History of changes: see https://github.com/go-chi/chi/compare/v5.0.9...v5.0.10 ## v5.0.9 (2023-07-13) @@ -306,7 +311,7 @@ Cheers all, happy coding! request-scoped values. We're very excited about the new context addition and are proud to introduce chi v2, a minimal and powerful routing package for building large HTTP services, with zero external dependencies. Chi focuses on idiomatic design and encourages the use of - stdlib HTTP handlers and middlwares. + stdlib HTTP handlers and middlewares. - chi v2 deprecates its `chi.Handler` interface and requires `http.Handler` or `http.HandlerFunc` - chi v2 stores URL routing parameters and patterns in the standard request context: `r.Context()` - chi v2 lower-level routing context is accessible by `chi.RouteContext(r.Context()) *chi.Context`, diff --git a/vendor/github.com/go-chi/chi/v5/README.md b/vendor/github.com/go-chi/chi/v5/README.md index 718e373f..4b1c99d1 100644 --- a/vendor/github.com/go-chi/chi/v5/README.md +++ b/vendor/github.com/go-chi/chi/v5/README.md @@ -494,7 +494,7 @@ Copyright (c) 2015-present [Peter Kieltyka](https://github.com/pkieltyka) Licensed under [MIT License](./LICENSE) -[GoDoc]: https://pkg.go.dev/github.com/go-chi/chi?tab=versions +[GoDoc]: https://pkg.go.dev/github.com/go-chi/chi/v5 [GoDoc Widget]: https://godoc.org/github.com/go-chi/chi?status.svg [Travis]: https://travis-ci.org/go-chi/chi [Travis Widget]: https://travis-ci.org/go-chi/chi.svg?branch=master diff --git a/vendor/github.com/go-chi/chi/v5/SECURITY.md b/vendor/github.com/go-chi/chi/v5/SECURITY.md new file mode 100644 index 00000000..7e937f87 --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/SECURITY.md @@ -0,0 +1,5 @@ +# Reporting Security Issues + +We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. + +To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/go-chi/chi/security/advisories/new) tab. diff --git a/vendor/github.com/go-chi/chi/v5/context.go b/vendor/github.com/go-chi/chi/v5/context.go index 88f8e221..82e5f289 100644 --- a/vendor/github.com/go-chi/chi/v5/context.go +++ b/vendor/github.com/go-chi/chi/v5/context.go @@ -60,7 +60,7 @@ type Context struct { URLParams RouteParams // Route parameters matched for the current sub-router. It is - // intentionally unexported so it cant be tampered. + // intentionally unexported so it can't be tampered. routeParams RouteParams // The endpoint routing pattern that matched the request URI path @@ -92,6 +92,7 @@ func (x *Context) Reset() { x.routeParams.Keys = x.routeParams.Keys[:0] x.routeParams.Values = x.routeParams.Values[:0] x.methodNotAllowed = false + x.methodsAllowed = x.methodsAllowed[:0] x.parentCtx = nil } @@ -113,18 +114,20 @@ func (x *Context) URLParam(key string) string { // // For example, // -// func Instrument(next http.Handler) http.Handler { -// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -// next.ServeHTTP(w, r) -// routePattern := chi.RouteContext(r.Context()).RoutePattern() -// measure(w, r, routePattern) -// }) -// } +// func Instrument(next http.Handler) http.Handler { +// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { +// next.ServeHTTP(w, r) +// routePattern := chi.RouteContext(r.Context()).RoutePattern() +// measure(w, r, routePattern) +// }) +// } func (x *Context) RoutePattern() string { routePattern := strings.Join(x.RoutePatterns, "") routePattern = replaceWildcards(routePattern) - routePattern = strings.TrimSuffix(routePattern, "//") - routePattern = strings.TrimSuffix(routePattern, "/") + if routePattern != "/" { + routePattern = strings.TrimSuffix(routePattern, "//") + routePattern = strings.TrimSuffix(routePattern, "/") + } return routePattern } diff --git a/vendor/github.com/go-chi/chi/v5/middleware/compress.go b/vendor/github.com/go-chi/chi/v5/middleware/compress.go index 773d47a1..28240c4b 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/compress.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/compress.go @@ -137,14 +137,14 @@ func NewCompressor(level int, types ...string) *Compressor { // // For example, add the Brotli algorithm: // -// import brotli_enc "gopkg.in/kothar/brotli-go.v0/enc" +// import brotli_enc "gopkg.in/kothar/brotli-go.v0/enc" // -// compressor := middleware.NewCompressor(5, "text/html") -// compressor.SetEncoder("br", func(w io.Writer, level int) io.Writer { -// params := brotli_enc.NewBrotliParams() -// params.SetQuality(level) -// return brotli_enc.NewBrotliWriter(params, w) -// }) +// compressor := middleware.NewCompressor(5, "text/html") +// compressor.SetEncoder("br", func(w io.Writer, level int) io.Writer { +// params := brotli_enc.NewBrotliParams() +// params.SetQuality(level) +// return brotli_enc.NewBrotliWriter(params, w) +// }) func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { encoding = strings.ToLower(encoding) if encoding == "" { @@ -156,12 +156,8 @@ func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { // If we are adding a new encoder that is already registered, we have to // clear that one out first. - if _, ok := c.pooledEncoders[encoding]; ok { - delete(c.pooledEncoders, encoding) - } - if _, ok := c.encoders[encoding]; ok { - delete(c.encoders, encoding) - } + delete(c.pooledEncoders, encoding) + delete(c.encoders, encoding) // If the encoder supports Resetting (IoReseterWriter), then it can be pooled. encoder := fn(ioutil.Discard, c.level) @@ -201,7 +197,7 @@ func (c *Compressor) Handler(next http.Handler) http.Handler { contentTypes: c.allowedTypes, contentWildcards: c.allowedWildcards, encoding: encoding, - compressable: false, // determined in post-handler + compressible: false, // determined in post-handler } if encoder != nil { cw.w = encoder @@ -275,10 +271,10 @@ type compressResponseWriter struct { contentWildcards map[string]struct{} encoding string wroteHeader bool - compressable bool + compressible bool } -func (cw *compressResponseWriter) isCompressable() bool { +func (cw *compressResponseWriter) isCompressible() bool { // Parse the first part of the Content-Type response header. contentType := cw.Header().Get("Content-Type") if idx := strings.Index(contentType, ";"); idx >= 0 { @@ -310,13 +306,13 @@ func (cw *compressResponseWriter) WriteHeader(code int) { return } - if !cw.isCompressable() { - cw.compressable = false + if !cw.isCompressible() { + cw.compressible = false return } if cw.encoding != "" { - cw.compressable = true + cw.compressible = true cw.Header().Set("Content-Encoding", cw.encoding) cw.Header().Add("Vary", "Accept-Encoding") @@ -334,11 +330,10 @@ func (cw *compressResponseWriter) Write(p []byte) (int, error) { } func (cw *compressResponseWriter) writer() io.Writer { - if cw.compressable { + if cw.compressible { return cw.w - } else { - return cw.ResponseWriter } + return cw.ResponseWriter } type compressFlusher interface { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/logger.go b/vendor/github.com/go-chi/chi/v5/middleware/logger.go index 98250d82..cff9bd20 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/logger.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/logger.go @@ -31,10 +31,11 @@ var ( // // IMPORTANT NOTE: Logger should go before any other middleware that may change // the response, such as middleware.Recoverer. Example: -// r := chi.NewRouter() -// r.Use(middleware.Logger) // <--<< Logger should come before Recoverer -// r.Use(middleware.Recoverer) -// r.Get("/", handler) +// +// r := chi.NewRouter() +// r.Use(middleware.Logger) // <--<< Logger should come before Recoverer +// r.Use(middleware.Recoverer) +// r.Get("/", handler) func Logger(next http.Handler) http.Handler { return DefaultLogger(next) } diff --git a/vendor/github.com/go-chi/chi/v5/middleware/nocache.go b/vendor/github.com/go-chi/chi/v5/middleware/nocache.go index 7353448d..9308d40d 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/nocache.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/nocache.go @@ -32,10 +32,11 @@ var etagHeaders = []string{ // a router (or subrouter) from being cached by an upstream proxy and/or client. // // As per http://wiki.nginx.org/HttpProxyModule - NoCache sets: -// Expires: Thu, 01 Jan 1970 00:00:00 UTC -// Cache-Control: no-cache, private, max-age=0 -// X-Accel-Expires: 0 -// Pragma: no-cache (for HTTP/1.0 proxies/clients) +// +// Expires: Thu, 01 Jan 1970 00:00:00 UTC +// Cache-Control: no-cache, private, max-age=0 +// X-Accel-Expires: 0 +// Pragma: no-cache (for HTTP/1.0 proxies/clients) func NoCache(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/profiler.go b/vendor/github.com/go-chi/chi/v5/middleware/profiler.go index 3c36f878..ebd81ee4 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/profiler.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/profiler.go @@ -2,7 +2,6 @@ package middleware import ( "expvar" - "fmt" "net/http" "net/http/pprof" @@ -11,13 +10,13 @@ import ( // Profiler is a convenient subrouter used for mounting net/http/pprof. ie. // -// func MyService() http.Handler { -// r := chi.NewRouter() -// // ..middlewares -// r.Mount("/debug", middleware.Profiler()) -// // ..routes -// return r -// } +// func MyService() http.Handler { +// r := chi.NewRouter() +// // ..middlewares +// r.Mount("/debug", middleware.Profiler()) +// // ..routes +// return r +// } func Profiler() http.Handler { r := chi.NewRouter() r.Use(NoCache) @@ -34,7 +33,7 @@ func Profiler() http.Handler { r.HandleFunc("/pprof/profile", pprof.Profile) r.HandleFunc("/pprof/symbol", pprof.Symbol) r.HandleFunc("/pprof/trace", pprof.Trace) - r.HandleFunc("/vars", expVars) + r.Handle("/vars", expvar.Handler()) r.Handle("/pprof/goroutine", pprof.Handler("goroutine")) r.Handle("/pprof/threadcreate", pprof.Handler("threadcreate")) @@ -45,18 +44,3 @@ func Profiler() http.Handler { return r } - -// Replicated from expvar.go as not public. -func expVars(w http.ResponseWriter, r *http.Request) { - first := true - w.Header().Set("Content-Type", "application/json") - fmt.Fprintf(w, "{\n") - expvar.Do(func(kv expvar.KeyValue) { - if !first { - fmt.Fprintf(w, ",\n") - } - first = false - fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) - }) - fmt.Fprintf(w, "\n}\n") -} diff --git a/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go b/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go index 612e155a..81342dfa 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go @@ -113,15 +113,14 @@ func (s prettyStack) decorateLine(line string, useColor bool, num int) (string, line = strings.TrimSpace(line) if strings.HasPrefix(line, "\t") || strings.Contains(line, ".go:") { return s.decorateSourceLine(line, useColor, num) - } else if strings.HasSuffix(line, ")") { + } + if strings.HasSuffix(line, ")") { return s.decorateFuncCallLine(line, useColor, num) - } else { - if strings.HasPrefix(line, "\t") { - return strings.Replace(line, "\t", " ", 1), nil - } else { - return fmt.Sprintf(" %s\n", line), nil - } } + if strings.HasPrefix(line, "\t") { + return strings.Replace(line, "\t", " ", 1), nil + } + return fmt.Sprintf(" %s\n", line), nil } func (s prettyStack) decorateFuncCallLine(line string, useColor bool, num int) (string, error) { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go b/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go index ea914a1d..997bed56 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go @@ -11,39 +11,34 @@ import ( // For example, lets say you'd like to setup multiple routers depending on the // request Host header, you could then do something as so: // -// r := chi.NewRouter() -// rSubdomain := chi.NewRouter() -// -// r.Use(middleware.RouteHeaders(). -// Route("Host", "example.com", middleware.New(r)). -// Route("Host", "*.example.com", middleware.New(rSubdomain)). -// Handler) -// -// r.Get("/", h) -// rSubdomain.Get("/", h2) -// +// r := chi.NewRouter() +// rSubdomain := chi.NewRouter() +// r.Use(middleware.RouteHeaders(). +// Route("Host", "example.com", middleware.New(r)). +// Route("Host", "*.example.com", middleware.New(rSubdomain)). +// Handler) +// r.Get("/", h) +// rSubdomain.Get("/", h2) // // Another example, imagine you want to setup multiple CORS handlers, where for // your origin servers you allow authorized requests, but for third-party public // requests, authorization is disabled. // -// r := chi.NewRouter() -// -// r.Use(middleware.RouteHeaders(). -// Route("Origin", "https://app.skyweaver.net", cors.Handler(cors.Options{ -// AllowedOrigins: []string{"https://api.skyweaver.net"}, -// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, -// AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, -// AllowCredentials: true, // <----------<<< allow credentials -// })). -// Route("Origin", "*", cors.Handler(cors.Options{ -// AllowedOrigins: []string{"*"}, -// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, -// AllowedHeaders: []string{"Accept", "Content-Type"}, -// AllowCredentials: false, // <----------<<< do not allow credentials -// })). -// Handler) -// +// r := chi.NewRouter() +// r.Use(middleware.RouteHeaders(). +// Route("Origin", "https://app.skyweaver.net", cors.Handler(cors.Options{ +// AllowedOrigins: []string{"https://api.skyweaver.net"}, +// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, +// AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, +// AllowCredentials: true, // <----------<<< allow credentials +// })). +// Route("Origin", "*", cors.Handler(cors.Options{ +// AllowedOrigins: []string{"*"}, +// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, +// AllowedHeaders: []string{"Accept", "Content-Type"}, +// AllowCredentials: false, // <----------<<< do not allow credentials +// })). +// Handler) func RouteHeaders() HeaderRouter { return HeaderRouter{} } @@ -150,11 +145,7 @@ func NewPattern(value string) Pattern { func (p Pattern) Match(v string) bool { if !p.wildcard { - if p.prefix == v { - return true - } else { - return false - } + return p.prefix == v } return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix) } diff --git a/vendor/github.com/go-chi/chi/v5/middleware/sunset.go b/vendor/github.com/go-chi/chi/v5/middleware/sunset.go new file mode 100644 index 00000000..18815d58 --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/middleware/sunset.go @@ -0,0 +1,25 @@ +package middleware + +import ( + "net/http" + "time" +) + +// Sunset set Deprecation/Sunset header to response +// This can be used to enable Sunset in a route or a route group +// For more: https://www.rfc-editor.org/rfc/rfc8594.html +func Sunset(sunsetAt time.Time, links ...string) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !sunsetAt.IsZero() { + w.Header().Set("Sunset", sunsetAt.Format(http.TimeFormat)) + w.Header().Set("Deprecation", sunsetAt.Format(http.TimeFormat)) + + for _, link := range links { + w.Header().Add("Link", link) + } + } + next.ServeHTTP(w, r) + }) + } +} diff --git a/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go b/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go new file mode 100644 index 00000000..83a8a872 --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go @@ -0,0 +1,27 @@ +package middleware + +import ( + "net/http" + + "github.com/go-chi/chi/v5" +) + +// SupressNotFound will quickly respond with a 404 if the route is not found +// and will not continue to the next middleware handler. +// +// This is handy to put at the top of your middleware stack to avoid unnecessary +// processing of requests that are not going to match any routes anyway. For +// example its super annoying to see a bunch of 404's in your logs from bots. +func SupressNotFound(router *chi.Mux) func(next http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + rctx := chi.RouteContext(r.Context()) + match := rctx.Routes.Match(rctx, r.Method, r.URL.Path) + if !match { + router.NotFoundHandler().ServeHTTP(w, r) + return + } + next.ServeHTTP(w, r) + }) + } +} diff --git a/vendor/github.com/go-chi/chi/v5/middleware/timeout.go b/vendor/github.com/go-chi/chi/v5/middleware/timeout.go index 8e373536..add596d6 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/timeout.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/timeout.go @@ -15,21 +15,20 @@ import ( // // ie. a route/handler may look like: // -// r.Get("/long", func(w http.ResponseWriter, r *http.Request) { -// ctx := r.Context() -// processTime := time.Duration(rand.Intn(4)+1) * time.Second +// r.Get("/long", func(w http.ResponseWriter, r *http.Request) { +// ctx := r.Context() +// processTime := time.Duration(rand.Intn(4)+1) * time.Second // -// select { -// case <-ctx.Done(): -// return +// select { +// case <-ctx.Done(): +// return // -// case <-time.After(processTime): -// // The above channel simulates some hard work. -// } -// -// w.Write([]byte("done")) -// }) +// case <-time.After(processTime): +// // The above channel simulates some hard work. +// } // +// w.Write([]byte("done")) +// }) func Timeout(timeout time.Duration) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/url_format.go b/vendor/github.com/go-chi/chi/v5/middleware/url_format.go index 919eb0fe..d8a651e4 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/url_format.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/url_format.go @@ -20,30 +20,29 @@ var ( // // Routers should not include a url parameter for the suffix when using this middleware. // -// Sample usage.. for url paths: `/articles/1`, `/articles/1.json` and `/articles/1.xml` +// Sample usage for url paths `/articles/1`, `/articles/1.json` and `/articles/1.xml`: // -// func routes() http.Handler { -// r := chi.NewRouter() -// r.Use(middleware.URLFormat) +// func routes() http.Handler { +// r := chi.NewRouter() +// r.Use(middleware.URLFormat) // -// r.Get("/articles/{id}", ListArticles) +// r.Get("/articles/{id}", ListArticles) // -// return r -// } +// return r +// } // -// func ListArticles(w http.ResponseWriter, r *http.Request) { -// urlFormat, _ := r.Context().Value(middleware.URLFormatCtxKey).(string) -// -// switch urlFormat { -// case "json": -// render.JSON(w, r, articles) -// case "xml:" -// render.XML(w, r, articles) -// default: -// render.JSON(w, r, articles) -// } -// } +// func ListArticles(w http.ResponseWriter, r *http.Request) { +// urlFormat, _ := r.Context().Value(middleware.URLFormatCtxKey).(string) // +// switch urlFormat { +// case "json": +// render.JSON(w, r, articles) +// case "xml:" +// render.XML(w, r, articles) +// default: +// render.JSON(w, r, articles) +// } +// } func URLFormat(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/vendor/github.com/go-chi/chi/v5/mux.go b/vendor/github.com/go-chi/chi/v5/mux.go index 977aa52d..735ab232 100644 --- a/vendor/github.com/go-chi/chi/v5/mux.go +++ b/vendor/github.com/go-chi/chi/v5/mux.go @@ -250,20 +250,19 @@ func (mx *Mux) With(middlewares ...func(http.Handler) http.Handler) Router { return im } -// Group creates a new inline-Mux with a fresh middleware stack. It's useful +// Group creates a new inline-Mux with a copy of middleware stack. It's useful // for a group of handlers along the same routing path that use an additional // set of middlewares. See _examples/. func (mx *Mux) Group(fn func(r Router)) Router { - im := mx.With().(*Mux) + im := mx.With() if fn != nil { fn(im) } return im } -// Route creates a new Mux with a fresh middleware stack and mounts it -// along the `pattern` as a subrouter. Effectively, this is a short-hand -// call to Mount. See _examples/. +// Route creates a new Mux and mounts it along the `pattern` as a subrouter. +// Effectively, this is a short-hand call to Mount. See _examples/. func (mx *Mux) Route(pattern string, fn func(r Router)) Router { if fn == nil { panic(fmt.Sprintf("chi: attempting to Route() a nil subrouter on '%s'", pattern)) diff --git a/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go b/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go index e9a732b8..365b270c 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go +++ b/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go @@ -115,6 +115,9 @@ type Entry struct { // Contains the instance's client meta if it's to be advertised as a DMSG Client. Client *Client `json:"client,omitempty"` + // ClientType the instance's client_type meta if it's to be advertised as a DMSG Client. + ClientType string `json:"client_type,omitempty"` + // Contains the instance's server meta if it's to be advertised as a DMSG Server. Server *Server `json:"server,omitempty"` @@ -167,6 +170,9 @@ type Server struct { // AvailableSessions is the number of available sessions that the server can currently accept. AvailableSessions int `json:"availableSessions"` + + // ServerType of DMSG Server, be `official` of `community` + ServerType string `json:"serverType,omitempty"` } // String implements stringer diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go index 27e86e1c..e6ad91a7 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "math/rand" "net" "sync" "time" @@ -31,10 +32,10 @@ type ClientCallbacks struct { func (sc *ClientCallbacks) ensure() { if sc.OnSessionDial == nil { - sc.OnSessionDial = func(network, addr string) (err error) { return nil } + sc.OnSessionDial = func(network, addr string) (err error) { return nil } //nolint } if sc.OnSessionDisconnect == nil { - sc.OnSessionDisconnect = func(network, addr string, err error) {} + sc.OnSessionDisconnect = func(network, addr string, err error) {} //nolint } } @@ -43,6 +44,7 @@ type Config struct { MinSessions int UpdateInterval time.Duration // Duration between discovery entry updates. Callbacks *ClientCallbacks + ClientType string } // Ensure ensures all config values are set. @@ -107,10 +109,9 @@ func NewClient(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Conf // Init callback: on set session. c.EntityCommon.setSessionCallback = func(ctx context.Context) error { - if err := c.EntityCommon.updateClientEntry(ctx, c.done); err != nil { + if err := c.EntityCommon.updateClientEntry(ctx, c.done, c.conf.ClientType); err != nil { return err } - // Client is 'ready' once we have successfully updated the discovery entry // with at least one delegated server. c.readyOnce.Do(func() { close(c.ready) }) @@ -119,7 +120,7 @@ func NewClient(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Conf // Init callback: on delete session. c.EntityCommon.delSessionCallback = func(ctx context.Context) error { - err := c.EntityCommon.updateClientEntry(ctx, c.done) + err := c.EntityCommon.updateClientEntry(ctx, c.done, c.conf.ClientType) return err } @@ -174,9 +175,18 @@ func (ce *Client) Serve(ctx context.Context) { entries = entries[ind : ind+1] } } + } else if ctx.Value("setupNode") != nil { + entries, err = ce.discoverServers(cancellabelCtx, true) + if err != nil { + ce.log.WithError(err).Warn("Failed to discover dmsg servers.") + if err == context.Canceled || err == context.DeadlineExceeded { + return + } + ce.serveWait() + continue + } } else { entries, err = ce.discoverServers(cancellabelCtx, false) - if err != nil { ce.log.WithError(err).Warn("Failed to discover dmsg servers.") if err == context.Canceled || err == context.DeadlineExceeded { @@ -190,7 +200,10 @@ func (ce *Client) Serve(ctx context.Context) { ce.log.Warnf("No entries found. Retrying after %s...", ce.bo.String()) ce.serveWait() } - + // randomize dmsg servers list + rand.Shuffle(len(entries), func(i, j int) { + entries[i], entries[j] = entries[j], entries[i] + }) for n, entry := range entries { if isClosed(ce.done) { return @@ -445,7 +458,7 @@ func (ce *Client) dialSession(ctx context.Context, entry *disc.Entry) (cs Client // AllStreams returns all the streams of the current client. func (ce *Client) AllStreams() (out []*Stream) { - fn := func(port uint16, pv netutil.PorterValue) (next bool) { + fn := func(port uint16, pv netutil.PorterValue) (next bool) { //nolint if str, ok := pv.Value.(*Stream); ok { out = append(out, str) return true @@ -472,6 +485,15 @@ func (ce *Client) AllEntries(ctx context.Context) (entries []string, err error) return entries, err } +// AllVisorEntries returns all the entries registered in discovery that are visor +func (ce *Client) AllVisorEntries(ctx context.Context) (entries []string, err error) { + err = netutil.NewDefaultRetrier(ce.log).Do(ctx, func() error { + entries, err = ce.dc.AllEntries(ctx) + return err + }) + return entries, err +} + // ConnectedServersPK return keys of all connected dmsg servers func (ce *Client) ConnectedServersPK() []string { sessions := ce.allClientSessions(ce.porter) diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go index 6b5e96f8..cac2c8b8 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go @@ -14,4 +14,8 @@ const ( DefaultMaxSessions = 100 DefaultDmsgHTTPPort = uint16(80) + + DefaultOfficialDmsgServerType = "official" + + DefaultCommunityDmsgServerType = "community" ) diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go index 9ead2b5d..ee0d9843 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go @@ -143,7 +143,7 @@ func (c *EntityCommon) delSession(ctx context.Context, pk cipher.PubKey) { // updateServerEntry updates the dmsg server's entry within dmsg discovery. // If 'addr' is an empty string, the Entry.addr field will not be updated in discovery. -func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSessions int) (err error) { +func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSessions int, authPassphrase string) (err error) { if addr == "" { panic("updateServerEntry cannot accept empty 'addr' input") // this should never happen } @@ -170,6 +170,10 @@ func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSe return errors.New("entry in discovery is not of a dmsg server") } + if authPassphrase != "" { + entry.Server.ServerType = authPassphrase + } + sessionsDelta := entry.Server.AvailableSessions != availableSessions addrDelta := entry.Server.Address != addr @@ -192,7 +196,7 @@ func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSe return c.dc.PutEntry(ctx, c.sk, entry) } -func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, maxSessions int) { +func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, maxSessions int, authPassphrase string) { t := time.NewTimer(c.updateInterval) defer t.Stop() @@ -208,7 +212,7 @@ func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, m } c.sessionsMx.Lock() - err := c.updateServerEntry(ctx, addr, maxSessions) + err := c.updateServerEntry(ctx, addr, maxSessions, authPassphrase) c.sessionsMx.Unlock() if err != nil { @@ -221,7 +225,7 @@ func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, m } } -func (c *EntityCommon) updateClientEntry(ctx context.Context, done chan struct{}) (err error) { +func (c *EntityCommon) updateClientEntry(ctx context.Context, done chan struct{}, clientType string) (err error) { if isClosed(done) { return nil } @@ -241,12 +245,13 @@ func (c *EntityCommon) updateClientEntry(ctx context.Context, done chan struct{} entry, err := c.dc.Entry(ctx, c.pk) if err != nil { entry = disc.NewClientEntry(c.pk, 0, srvPKs) + entry.ClientType = clientType if err := entry.Sign(c.sk); err != nil { return err } return c.dc.PostEntry(ctx, entry) } - + entry.ClientType = clientType entry.Client.DelegatedServers = srvPKs c.log.WithField("entry", entry).Debug("Updating entry.") return c.dc.PutEntry(ctx, c.sk, entry) diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go index af40b75a..1245d2e5 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go @@ -21,6 +21,7 @@ type ServerConfig struct { MaxSessions int UpdateInterval time.Duration LimitIP int + AuthPassphrase string } // DefaultServerConfig returns the default server config. @@ -54,6 +55,8 @@ type Server struct { limitIP int ipCounter map[string]int ipCounterLocker sync.RWMutex + + authPassphrase string } // NewServer creates a new dmsg server entity. @@ -74,13 +77,14 @@ func NewServer(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Serv s.addrDone = make(chan struct{}) s.maxSessions = conf.MaxSessions s.setSessionCallback = func(ctx context.Context) error { - return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions) + return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions, conf.AuthPassphrase) } s.delSessionCallback = func(ctx context.Context) error { - return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions) + return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions, conf.AuthPassphrase) } s.ipCounter = make(map[string]int) s.limitIP = conf.LimitIP + s.authPassphrase = conf.AuthPassphrase return s } @@ -186,13 +190,13 @@ func (s *Server) Serve(lis net.Listener, addr string) error { func (s *Server) startUpdateEntryLoop(ctx context.Context) error { err := netutil.NewDefaultRetrier(s.log).Do(ctx, func() error { - return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions) + return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions, s.authPassphrase) }) if err != nil { return err } - go s.updateServerEntryLoop(ctx, s.AdvertisedAddr(), s.maxSessions) + go s.updateServerEntryLoop(ctx, s.AdvertisedAddr(), s.maxSessions, s.authPassphrase) return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index 7c6c7804..b297c37f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -158,7 +158,7 @@ github.com/gin-gonic/gin/binding github.com/gin-gonic/gin/internal/bytesconv github.com/gin-gonic/gin/internal/json github.com/gin-gonic/gin/render -# github.com/go-chi/chi/v5 v5.0.10 +# github.com/go-chi/chi/v5 v5.0.11 ## explicit; go 1.14 github.com/go-chi/chi/v5 github.com/go-chi/chi/v5/middleware @@ -455,7 +455,7 @@ github.com/rs/cors ## explicit; go 1.13 github.com/sirupsen/logrus github.com/sirupsen/logrus/hooks/syslog -# github.com/skycoin/dmsg v1.3.14 +# github.com/skycoin/dmsg v1.3.14 => github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4 ## explicit; go 1.21 github.com/skycoin/dmsg/internal/servermetrics github.com/skycoin/dmsg/pkg/direct @@ -826,3 +826,4 @@ nhooyr.io/websocket/internal/bpool nhooyr.io/websocket/internal/errd nhooyr.io/websocket/internal/wsjs nhooyr.io/websocket/internal/xsync +# github.com/skycoin/dmsg => github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4