diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 413c8ba6b..6647c854e 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -1,5 +1,5 @@ require "log4r" -require "vagrant/util/credential_scrubber" + # Update the default formatter within the log4r library to ensure # sensitive values are being properly scrubbed from logger data class Log4r::BasicFormatter @@ -20,12 +20,33 @@ module Vagrant # outside of command implementations to the local option # parser instances in use class OptionParser < ::OptionParser + + attr_reader :flags + def initialize(*_) + @flags = [] super Vagrant.default_cli_options.each do |opt_proc| opt_proc.call(self) end end + + def on(*opts, &block) + super + # TODO: make this not a disaster + if opts[0][0,2] == "--" + ln = opts[0].split(" ")[0][2..-1] + else + ln = opts[1].split(" ")[0][2..-1] + end + @flags.append( + { + long_name: ln, + description: opts[-1], + type: String + } + ) + end end end diff --git a/plugins/commands/port/command.rb b/plugins/commands/port/command.rb index dc27e43af..39fd39c06 100644 --- a/plugins/commands/port/command.rb +++ b/plugins/commands/port/command.rb @@ -23,8 +23,6 @@ module VagrantPlugins o.on("--guest PORT", "Output the host port that maps to the given guest port") do |port| options[:guest] = port end - - o.on("--machine-readable", "Display machine-readable output") end # Parse the options diff --git a/plugins/commands/serve/service/command_service.rb b/plugins/commands/serve/service/command_service.rb index 47dc01413..40552a6f9 100644 --- a/plugins/commands/serve/service/command_service.rb +++ b/plugins/commands/serve/service/command_service.rb @@ -47,17 +47,26 @@ module VagrantPlugins if !plugin raise "Failed to locate command plugin for: #{plugin_name}" end - # klass = Class.new(plugin.call) - # klass.class_eval { - # } - Hashicorp::Vagrant::Sdk::Command::FlagsResp.new( - flags: [ + $stashed_opts = nil + klass = Class.new(plugin.call) + klass.class_eval { def parse_options(opts); $stashed_opts = opts; nil; end }; + klass.new(['-h'], {}).execute + flags = [] + $stashed_opts.flags.each do |opt| + flags.append( Hashicorp::Vagrant::Sdk::Command::Flag.new( - long_name: "test", short_name: "t", - description: "does this even work?", default_value: "true", + long_name: opt[:long_name], + description: opt[:description], type: Hashicorp::Vagrant::Sdk::Command::Flag::Type::BOOL - ) - ] + )) + # Hashicorp::Vagrant::Sdk::Command::Flag.new( + # long_name: "test", short_name: "t", + # description: "does this even work?", default_value: "true", + # type: Hashicorp::Vagrant::Sdk::Command::Flag::Type::BOOL + # ) + end + Hashicorp::Vagrant::Sdk::Command::FlagsResp.new( + flags: flags ) end end