aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)
+ }
+ }
+}