From 65d990efc999a9ed4e11633da98089bb37cc65cc Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 8 Apr 2021 17:40:50 -0500 Subject: [PATCH] Start gatching subcommands to register --- builtin/myplugin/command.go | 9 +++++++++ internal/core/basis.go | 9 +++++++++ plugins/commands/serve/service/command_service.rb | 7 +++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/builtin/myplugin/command.go b/builtin/myplugin/command.go index b714fc36f..a2013939c 100644 --- a/builtin/myplugin/command.go +++ b/builtin/myplugin/command.go @@ -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") diff --git a/internal/core/basis.go b/internal/core/basis.go index f01cafcbe..b013ec1ee 100644 --- a/internal/core/basis.go +++ b/internal/core/basis.go @@ -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{ diff --git a/plugins/commands/serve/service/command_service.rb b/plugins/commands/serve/service/command_service.rb index 852f5e699..3e18f4e1e 100644 --- a/plugins/commands/serve/service/command_service.rb +++ b/plugins/commands/serve/service/command_service.rb @@ -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)