aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJavier Peletier <jpeletier@users.noreply.github.com>2018-07-17 13:04:43 +0800
committerAnton Evangelatov <anton.evangelatov@gmail.com>2018-07-23 21:33:32 +0800
commit7ddc2c9e95ac2b46cf84ef9776173ad70b5117cd (patch)
treeb7915226cadfca0b69e2d97375aa3a6d6587985f /cmd
parentdcaaa3c804c302126fb0b9c9ded7c23f21995f4b (diff)
downloaddexon-7ddc2c9e95ac2b46cf84ef9776173ad70b5117cd.tar.gz
dexon-7ddc2c9e95ac2b46cf84ef9776173ad70b5117cd.tar.zst
dexon-7ddc2c9e95ac2b46cf84ef9776173ad70b5117cd.zip
cmd/swarm: add implicit subcommand help (fix #786) (#788)
* cmd/swarm: add implicit subcommand help (fix #786) * cmd/swarm: moved implicit help to a recursive func
Diffstat (limited to 'cmd')
-rw-r--r--cmd/swarm/main.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go
index 5b0767951..d66191628 100644
--- a/cmd/swarm/main.go
+++ b/cmd/swarm/main.go
@@ -190,6 +190,15 @@ var (
SWARM_ERR_SWAP_SET_NO_API = "SWAP is enabled but --swap-api is not set"
)
+// this help command gets added to any subcommand that does not define it explicitly
+var defaultSubcommandHelp = cli.Command{
+ Action: func(ctx *cli.Context) { cli.ShowCommandHelpAndExit(ctx, "", 1) },
+ CustomHelpTemplate: helpTemplate,
+ Name: "help",
+ Usage: "shows this help",
+ Hidden: true,
+}
+
var defaultNodeConfig = node.DefaultConfig
// This init function sets defaults so cmd/swarm can run alongside geth.
@@ -377,6 +386,11 @@ pv(1) tool to get a progress bar:
// See config.go
DumpConfigCommand,
}
+
+ // append a hidden help subcommand to all commands that have subcommands
+ // if a help command was already defined above, that one will take precedence.
+ addDefaultHelpSubcommands(app.Commands)
+
sort.Sort(cli.CommandsByName(app.Commands))
app.Flags = []cli.Flag{
@@ -613,3 +627,16 @@ func injectBootnodes(srv *p2p.Server, nodes []string) {
srv.AddPeer(n)
}
}
+
+// addDefaultHelpSubcommand scans through defined CLI commands and adds
+// a basic help subcommand to each
+// if a help command is already defined, it will take precedence over the default.
+func addDefaultHelpSubcommands(commands []cli.Command) {
+ for i := range commands {
+ cmd := &commands[i]
+ if cmd.Subcommands != nil {
+ cmd.Subcommands = append(cmd.Subcommands, defaultSubcommandHelp)
+ addDefaultHelpSubcommands(cmd.Subcommands)
+ }
+ }
+}