aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/installer/managers/nuget.lua
blob: 2b864163f9e21fa3fe89de5774bbe0a8880255e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local Result = require "mason-core.result"
local installer = require "mason-core.installer"
local log = require "mason-core.log"
local platform = require "mason-core.platform"

local M = {}

---@async
---@param package string
---@param version string
---@nodiscard
function M.install(package, version)
    log.fmt_debug("nuget: install %s %s", package, version)
    local ctx = installer.context()
    ctx.stdio_sink:stdout(("Installing nuget package %s@%s…\n"):format(package, version))
    return ctx.spawn.dotnet {
        "tool",
        "update",
        "--tool-path",
        ".",
        { "--version", version },
        package,
    }
end

---@param bin string
function M.bin_path(bin)
    return Result.pcall(platform.when, {
        unix = function()
            return bin
        end,
        win = function()
            local ctx = installer.context()
            local shim = ("%s.cmd"):format(bin)
            if ctx.fs:file_exists(shim) then
                return shim
            else
                return ("%s.exe"):format(bin)
            end
        end,
    })
end

return M