|
6 | 6 | "github.com/apex/log"
|
7 | 7 | "github.com/spf13/cobra"
|
8 | 8 | "github.com/tarantool/tt/cli/modules"
|
9 |
| - "github.com/tarantool/tt/cli/util" |
10 | 9 | )
|
11 | 10 |
|
12 | 11 | // ExternalCmd configures external commands.
|
@@ -49,34 +48,37 @@ func configureNonExistentCmd(rootCmd *cobra.Command,
|
49 | 48 | }
|
50 | 49 | }
|
51 | 50 |
|
52 |
| - helpCmd := util.GetHelpCommand(rootCmd) |
53 | 51 | externalCmdPath := rootCmd.Name() + " " + externalCmd
|
54 | 52 | if _, found := (*modulesInfo)[externalCmdPath]; found {
|
55 | 53 | rootCmd.AddCommand(newExternalCommand(modulesInfo, externalCmd,
|
56 |
| - externalCmdPath, nil)) |
57 |
| - helpCmd.AddCommand(newExternalCommand(modulesInfo, externalCmd, externalCmdPath, |
58 |
| - []string{"--help"})) |
| 54 | + externalCmdPath)) |
59 | 55 | }
|
60 | 56 | }
|
61 | 57 |
|
| 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 | + |
62 | 68 | // newExternalCommand returns a pointer to a new external
|
63 | 69 | // command that will call modules.RunCmd.
|
64 | 70 | func newExternalCommand(modulesInfo *modules.ModulesInfo,
|
65 |
| - cmdName, cmdPath string, addArgs []string) *cobra.Command { |
| 71 | + cmdName, cmdPath string) *cobra.Command { |
66 | 72 | cmd := &cobra.Command{
|
67 | 73 | Use: cmdName,
|
68 | 74 | Run: func(cmd *cobra.Command, args []string) {
|
69 |
| - if addArgs != nil { |
70 |
| - args = append(args, addArgs...) |
71 |
| - } |
72 |
| - |
73 | 75 | cmdCtx.Cli.ForceInternal = false
|
74 | 76 | if err := modules.RunCmd(&cmdCtx, cmdPath, modulesInfo, nil, args); err != nil {
|
75 | 77 | log.Fatalf(err.Error())
|
76 | 78 | }
|
77 | 79 | },
|
78 | 80 | }
|
79 |
| - |
80 | 81 | cmd.DisableFlagParsing = true
|
| 82 | + cmd.SetHelpFunc(externalCmdHelpFunc) |
81 | 83 | return cmd
|
82 | 84 | }
|
0 commit comments