Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api/command): accept boolean option notation #967

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lua/mason/api/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ local function join_handles(handles)
end

---@param package_specifiers string[]
---@param opts? { debug: boolean }
---@param opts? PackageInstallOpts
local function MasonInstall(package_specifiers, opts)
opts = opts or {}
local Package = require "mason-core.package"
Expand All @@ -97,7 +97,12 @@ local function MasonInstall(package_specifiers, opts)
local install_packages = _.map(function(pkg_specifier)
local package_name, version = Package.Parse(pkg_specifier)
local pkg = registry.get_package(package_name)
return pkg:install { version = version, debug = opts.debug }
return pkg:install {
version = version,
debug = opts.debug,
force = opts.force,
target = opts.target,
}
end)

if is_headless then
Expand All @@ -114,11 +119,22 @@ local function MasonInstall(package_specifiers, opts)
end
end

local parse_opts = _.compose(
_.from_pairs,
_.map(_.compose(function(arg)
if #arg == 2 then
return arg
else
return { arg[1], true }
end
end, _.split "=", _.gsub("^%-%-", "")))
)

---@param args string[]
---@return table<string, true> opts, string[] args
---@return table<string, true|string> opts, string[] args
local function parse_args(args)
local opts_list, args = unpack(_.partition(_.starts_with "--", args))
local opts = _.set_of(_.map(_.gsub("^%-%-", ""), opts_list))
local opts = parse_opts(opts_list)
return opts, args
end

Expand Down