Collect flag information

This commit is contained in:
sophia 2021-01-26 16:58:38 -06:00 committed by Paul Hinze
parent 43e4e968ef
commit 1109d89616
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 40 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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