Chain command after optional "--" #334
-
Hey. I'm trying to write completions for aws-vault, but the question is probably applicable to other software as well. What is the best way to match either of:
The skeleton of the script representing the question is pasted below (the whole script is at https://gist.github.com/elieux/cb864345878f501ff8fe1ab728d52e01). I tried various modifications unsuccessfully and this is the only one that worked at least somewhat. Problems are: it covers only the second case and it doesn't suggest using "--". local function profile()
return { "foo", "bar" } -- this is actually found out dynamically
end
clink.argmatcher("aws-vault")
:addflags("--foo")
:addarg({
"exec" .. clink.argmatcher()
:addflags("--bar")
:addarg(profile)
:addflags(
"--" .. clink.argmatcher():chaincommand()
)
:nofiles(),
})
:nofiles() |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 12 replies
-
I'm having trouble following the question, because I don't know anything about I think you mean that And I think you mean that On the argmatcher that's linked to |
Beta Was this translation helpful? Give feedback.
-
And regarding not suggesting |
Beta Was this translation helpful? Give feedback.
-
Oops, my mistake: I said to replace For now you can use But also, This script does what I think are you describing: local function profile()
return { "foo", "bar" } -- this is actually found out dynamically
end
local exec_parser = clink.argmatcher()
:addflags(
"--bar",
"--" .. clink.argmatcher():chaincommand()
)
:addarg(profile)
:chaincommand()
clink.argmatcher("aws-vault")
:addflags("--foo")
:addarg({"exec" .. exec_parser})
:nofiles() Note: I rearranged things a little, just for clarity. For example, Did you want for It's possible, but it's not easy. Currently you'd have to use make the |
Beta Was this translation helpful? Give feedback.
-
You're right, it's possible, but not in an obvious way. If I naively match a profile arg, then the local function profile()
return { "foo", "bar" } -- this is actually found out dynamically
end
clink.argmatcher("aws-vault")
:addflags("--foo")
:addarg({
"exec" .. clink.argmatcher()
:addflags("--bar")
:addarg(profile)
:addarg({ "--" }) -- same result if I link clink.argmatcher():chaincommand():nofiles() here
:chaincommand():nofiles(),
})
:nofiles() It works (completes local map = require("funclib").map
local function profile()
return { "foo", "bar" } -- this is actually found out dynamically
end
clink.argmatcher("aws-vault")
:addflags("--foo")
:addarg({
"exec" .. clink.argmatcher()
:addflags("--bar")
:addarg({ delayinit=function()
return map(profile(), function(item)
return item .. clink.argmatcher()
:addarg({ "--" }) -- same result if I link clink.argmatcher():chaincommand():nofiles() here
:chaincommand():nofiles()
end)
end })
:nofiles(),
})
:nofiles() Given my current understanding of args, I don't see why the first example fails. The second example is more complicated and also cannot continue with completion without exactly matching an existing profile.
I was hoping it would:
There's also the question of how to make |
Beta Was this translation helpful? Give feedback.
-
@elieux Based on the discussion here, I've made several changes to the docs for Argument Completion. Please take a look and share feedback on the new content. Thanks! |
Beta Was this translation helpful? Give feedback.
Oops, my mistake:
I said to replace
:nofiles()
with:chaincommand()
. But there is a bug that in some cases falls back to the "parent" argmatcher by mistake if:nofiles()
isn't used as well.For now you can use
:chaincommand():nofiles()
. And the next Clink update will include a fix so that the:nofiles()
isn't needed (it should be implied by:chaincommand()
).But also,
aws-vault exec foo
Tab will behave as thoughexec.enable
is False, due to a bug that is already fixed for the upcoming v1.3.40 release. It chains correctly, it just didn't respectexec.enable
correctly after chaining.This script does what I think are you describing: