Skip to content

Commit 6b0912e

Browse files
committed
external: implement help over cmd.SetHelp rather than help subcommand
Part of #1136
1 parent 06a2340 commit 6b0912e

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

cli/cmd/external.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/apex/log"
77
"github.com/spf13/cobra"
88
"github.com/tarantool/tt/cli/modules"
9-
"github.com/tarantool/tt/cli/util"
109
)
1110

1211
// ExternalCmd configures external commands.
@@ -49,34 +48,37 @@ func configureNonExistentCmd(rootCmd *cobra.Command,
4948
}
5049
}
5150

52-
helpCmd := util.GetHelpCommand(rootCmd)
5351
externalCmdPath := rootCmd.Name() + " " + externalCmd
5452
if _, found := (*modulesInfo)[externalCmdPath]; found {
5553
rootCmd.AddCommand(newExternalCommand(modulesInfo, externalCmd,
56-
externalCmdPath, nil))
57-
helpCmd.AddCommand(newExternalCommand(modulesInfo, externalCmd, externalCmdPath,
58-
[]string{"--help"}))
54+
externalCmdPath))
5955
}
6056
}
6157

58+
func externalCmdHelpFunc(cmd *cobra.Command, args []string) {
59+
module := modulesInfo[cmd.CommandPath()]
60+
helpMsg, err := modules.GetExternalModuleHelp(module.Main)
61+
if err != nil {
62+
cmd.PrintErr(err)
63+
return
64+
}
65+
cmd.Print(helpMsg)
66+
}
67+
6268
// newExternalCommand returns a pointer to a new external
6369
// command that will call modules.RunCmd.
6470
func newExternalCommand(modulesInfo *modules.ModulesInfo,
65-
cmdName, cmdPath string, addArgs []string) *cobra.Command {
71+
cmdName, cmdPath string) *cobra.Command {
6672
cmd := &cobra.Command{
6773
Use: cmdName,
6874
Run: func(cmd *cobra.Command, args []string) {
69-
if addArgs != nil {
70-
args = append(args, addArgs...)
71-
}
72-
7375
cmdCtx.Cli.ForceInternal = false
7476
if err := modules.RunCmd(&cmdCtx, cmdPath, modulesInfo, nil, args); err != nil {
7577
log.Fatalf(err.Error())
7678
}
7779
},
7880
}
79-
8081
cmd.DisableFlagParsing = true
82+
cmd.SetHelpFunc(externalCmdHelpFunc)
8183
return cmd
8284
}

0 commit comments

Comments
 (0)