Last active
August 19, 2022 08:46
-
-
Save elieux/cb864345878f501ff8fe1ab728d52e01 to your computer and use it in GitHub Desktop.
clink/completions/aws-vault.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local map = require("funclib").map | |
local strings = require("strings") | |
local sys = require("sys") | |
local function profile() | |
return sys.exec("aws-vault list --profiles") | |
end | |
local function backend() | |
local list = {} | |
local inside = false | |
for _, line in ipairs(sys.exec("aws-vault help 2>&1")) do | |
if strings.starts_with(line, " --backend=") then | |
inside = true | |
line = string.gsub(line, ".+%[", "") | |
end | |
if inside then | |
string.gsub(line, "(%a+)", function(item) | |
table.insert(list, item) | |
end) | |
end | |
if strings.ends_with(line, "]") then | |
inside = false | |
end | |
end | |
return list | |
end | |
local function prompt() | |
local list = {} | |
local inside = false | |
for _, line in ipairs(sys.exec("aws-vault help 2>&1")) do | |
if strings.starts_with(line, " --prompt=") then | |
inside = true | |
line = string.gsub(line, ".+%[", "") | |
end | |
if inside then | |
string.gsub(line, "(%a+)", function(item) | |
table.insert(list, item) | |
end) | |
end | |
if strings.ends_with(line, "]") then | |
inside = false | |
end | |
end | |
return list | |
end | |
local function region() | |
return { | |
"us-east-2", | |
"us-east-1", | |
"us-west-1", | |
"us-west-2", | |
"af-south-1", | |
"ap-east-1", | |
"ap-southeast-3", | |
"ap-south-1", | |
"ap-northeast-3", | |
"ap-northeast-2", | |
"ap-southeast-1", | |
"ap-southeast-2", | |
"ap-northeast-1", | |
"ca-central-1", | |
"cn-north-1", | |
"cn-northwest-1", | |
"eu-central-1", | |
"eu-west-1", | |
"eu-west-2", | |
"eu-south-1", | |
"eu-west-3", | |
"eu-north-1", | |
"me-south-1", | |
"sa-east-1", | |
} | |
end | |
clink.argmatcher("aws-vault") | |
:addflags( | |
"--help", | |
"--help-long", | |
"--help-man", | |
"--version", | |
"--debug", | |
"--backend=" .. clink.argmatcher():addarg(backend), | |
"--prompt=" .. clink.argmatcher():addarg(prompt), | |
"--keychain=", | |
"--secret-service-collection=", | |
"--pass-dir=" .. clink.argmatcher():addarg(clink.dirmatches), | |
"--pass-cmd=", | |
"--pass-prefix=", | |
"--file-dir=" .. clink.argmatcher():addarg(clink.dirmatches) | |
) | |
:addarg({ | |
"help" .. clink.argmatcher() | |
:addarg({ | |
"help", | |
"add", | |
"list", | |
"rotate", | |
"exec", | |
"clear", | |
"remove", | |
"login", | |
}) | |
:nofiles(), | |
"add" .. clink.argmatcher() | |
:addflags( | |
"--env", | |
"--add-config" | |
) | |
:nofiles(), | |
"list" .. clink.argmatcher() | |
:addflags( | |
"--profiles", | |
"--sessions", | |
"--credentials" | |
) | |
:nofiles(), | |
"rotate" .. clink.argmatcher() | |
:addflags( | |
"-n", "--no-session" | |
) | |
:addarg(profile) | |
:nofiles(), | |
"exec" .. clink.argmatcher() | |
:addflags( | |
"-d", "--duration=", | |
"-n", "--no-session", | |
"--region=" .. clink.argmatcher():addarg(region), | |
"-t", "--mfa-token=", | |
"-j", "--json", | |
"-s", "--server", | |
"--ec2-server", | |
"--ecs-server", | |
"--lazy", | |
"--stdout" | |
) | |
:addarg({ delayinit=function() | |
return map(profile(), function(item) | |
return item .. clink.argmatcher() | |
:addflags( | |
"--" .. clink.argmatcher():chaincommand():nofiles() | |
):chaincommand():nofiles() | |
end) | |
end }) | |
:nofiles(), | |
"clear" .. clink.argmatcher() | |
:addarg(profile) | |
:nofiles(), | |
"remove" .. clink.argmatcher() | |
:addflags( | |
"-f", "--force" | |
) | |
:addarg(profile) | |
:nofiles(), | |
"login" .. clink.argmatcher() | |
:addflags( | |
"-d", "--duration=", | |
"-n", "--no-session", | |
"-t", "--mfa-token=", | |
"--path=", | |
"--region=" .. clink.argmatcher():addarg(region), | |
"--stdout" | |
) | |
:addarg(profile) | |
:nofiles(), | |
}) | |
:nofiles() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment