Start gatching subcommands to register

This commit is contained in:
sophia 2021-04-08 17:40:50 -05:00 committed by Paul Hinze
parent 072e06ca79
commit 65d990efc9
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 21 additions and 4 deletions

View File

@ -60,6 +60,11 @@ func (c *Command) ExecuteFunc() interface{} {
return c.Execute
}
// HelpFunc implements component.Command
func (c *Command) SubcommandsFunc() interface{} {
return c.Subcommands
}
func (c *Command) Synopsis() string {
return "I don't really do anything"
}
@ -82,6 +87,10 @@ func (c *Command) Flags() []*option.Option {
return []*option.Option{booltest, stringflag}
}
func (c *Command) Subcommands() []*plugincore.Command {
return nil
}
func (c *Command) Execute(trm terminal.UI, env plugincore.Project) int64 {
mn, _ := env.MachineNames()
trm.Output("\nMachines in this project")

View File

@ -110,6 +110,15 @@ func (b *Basis) Init() (result *vagrant_server.Job_InitResult, err error) {
if err != nil {
b.logger.Error("failed to get flags for command "+name, "error", err)
}
subcmds, err := cmd.Subcommands()
if subcmds != nil {
for _, scmd := range subcmds {
b.logger.Info(scmd.Help())
}
}
if err != nil {
b.logger.Error("subcommand error", err)
}
result.Commands = append(
result.Commands,
&vagrant_server.Job_Command{

View File

@ -89,7 +89,7 @@ module VagrantPlugins
def subcommands
@subcommands
end
# Update the option parsing to store the provided options, and then return
# a nil value. The nil return will force the command to call help and not
# actually execute anything.
@ -118,13 +118,13 @@ module VagrantPlugins
# Create a new anonymous class based on the command class
# so we can modify the setup behavior
klass = augment_cmd_class(Class.new(plugin.call))
# If we don't have a backup reference to the original
# lets start with making one of those
if !VagrantPlugins.const_defined?(:VagrantOriginalOptionParser)
VagrantPlugins.const_set(:VagrantOriginalOptionParser, VagrantPlugins.const_get(:OptionParser))
end
# Now we need a customized class to get the new behavior
# that we want
optparse_klass = Class.new(VagrantPlugins.const_get(:VagrantOriginalOptionParser)) do
@ -160,7 +160,6 @@ module VagrantPlugins
end
options = Thread.current.thread_variable_get(:command_options)
msg = Thread.current.thread_variable_get(:command_info)
# Clean our option data out of the thread
Thread.current.thread_variable_set(:command_options, nil)