aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-02-05 01:36:00 +0100
committerGitHub <noreply@github.com>2023-02-05 01:36:00 +0100
commit47fdf54d622bde33391fe7fed6f5b74d0846b7c8 (patch)
treec5f86200363eb12c0aeebb879d1dc77d95e50a6a /lua
parentrefactor(std): remove zstd from untar (#966) (diff)
downloadmason-47fdf54d622bde33391fe7fed6f5b74d0846b7c8.tar
mason-47fdf54d622bde33391fe7fed6f5b74d0846b7c8.tar.gz
mason-47fdf54d622bde33391fe7fed6f5b74d0846b7c8.tar.bz2
mason-47fdf54d622bde33391fe7fed6f5b74d0846b7c8.tar.lz
mason-47fdf54d622bde33391fe7fed6f5b74d0846b7c8.tar.xz
mason-47fdf54d622bde33391fe7fed6f5b74d0846b7c8.tar.zst
mason-47fdf54d622bde33391fe7fed6f5b74d0846b7c8.zip
feat(api/command): accept boolean option notation (#967)
Now supports passing options such as `:MasonInstall --force --debug`, which will translate to the following install opt table: ```lua { "force" = true, "debug" = true } ```
Diffstat (limited to 'lua')
-rw-r--r--lua/mason/api/command.lua24
1 files changed, 20 insertions, 4 deletions
diff --git a/lua/mason/api/command.lua b/lua/mason/api/command.lua
index 3343ea1d..5d09c67d 100644
--- a/lua/mason/api/command.lua
+++ b/lua/mason/api/command.lua
@@ -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"
@@ -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
@@ -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