Skip to content

Commit e7b9f08

Browse files
Fix issue when passing arguments (#3213)
1 parent cc0afab commit e7b9f08

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/plugin/plugin.go

+11
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ func (p *Plugin) GetCobraCommands() []*cobra.Command {
174174
RunE: p.Run,
175175
}
176176

177+
// Disable the default cobra help function.
178+
// Instead redirect help to the plugin.
179+
// Example: atlas example-plugin --help -> [example-binary] example-plugin --help
180+
command.SetHelpFunc(func(cmd *cobra.Command, args []string) {
181+
// args contains all arguments + the name of the command
182+
// we don't need the name of the subcommand
183+
if err := p.Run(cmd, args[1:]); err != nil {
184+
_, _ = log.Warningf("failed to generate help for plugin command '%v': %v", args[0], err)
185+
}
186+
})
187+
177188
commands = append(commands, command)
178189
}
179190

0 commit comments

Comments
 (0)