Skip to content

Commit

Permalink
Add support for when one-letter flags can be concatenated.
Browse files Browse the repository at this point in the history
E.g. `git diff -awW` or `xcopy /hkf`.
  • Loading branch information
chrisant996 committed Aug 10, 2024
1 parent fc951ef commit db9ed23
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 61 deletions.
20 changes: 14 additions & 6 deletions completions/dirx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ end
-- IMPORTANT: If slash_flags has an onarg callback, then it will replace the one
-- from minus_flags, which would mess up both the DIRXCMD processing and also
-- the hide_unless stuff in general.
local minus_flags = { onarg=onarg_dirxcmd }
local slash_flags = {}
local minus_flags = { concat_one_letter_flags=true, onarg=onarg_dirxcmd }
local slash_flags = { concat_one_letter_flags=true }
local one_letter_flags = {}

local function copy_vars(entry, tbl)
tbl.hide = entry.hide
Expand All @@ -333,11 +334,13 @@ for _, entry in ipairs(list_of_flags) do
local slash = entry[1]:gsub("^%-", "/")
local long = entry[1]:find("^%-%-") and true

local num = #entry
if num == 2 or num == 3 then
local len = #entry
if len == 2 or len == 3 then
table.insert(minus_flags, copy_vars(entry, { minus, entry[2] }))
table.insert(slash_flags, copy_vars(entry, { slash, entry[2] }))
elseif num == 4 or long then
if not long then
table.insert(slash_flags, copy_vars(entry, { slash, entry[2] }))
end
elseif len == 4 or long then
if entry[2] then
table.insert(minus_flags, copy_vars(entry, { minus..entry[2], entry[3], entry[4] }))
else
Expand All @@ -349,6 +352,11 @@ for _, entry in ipairs(list_of_flags) do
else
error("unrecognized flag entry format.")
end

if not long then
table.insert(one_letter_flags, minus)
table.insert(one_letter_flags, slash)
end
end

clink.argmatcher("dirx")
Expand Down
7 changes: 6 additions & 1 deletion completions/reg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,17 @@ local add = clink.argmatcher():_addexflags({
:nofiles()

local delete = clink.argmatcher():_addexflags({
onarg=onarg_keyname,
common_flags,
{ "/v"..valuename, " ValueName", "Delete value name under the specified key" },
{ "/ve", "Delete the value of empty value name (Default)" },
{ "/va", "Delete all values under the specified key" },
{ "/f", "Forces deletion without prompt" },
})
:addarg(keyname_any)
:addarg({
onarg=onarg_keyname,
keyname_any,
})
:nofiles()

local copy = clink.argmatcher():_addexflags({
Expand Down
20 changes: 19 additions & 1 deletion completions/xcopy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,22 @@ if not clink_version.supports_argmatcher_delayinit then
return
end

require('help_parser').make('xcopy', '/?')
local function closure(parser)
-- This is a dirty hack. I don't want to invest in a reusable clean
-- mechanism right now.
if parser._flags and parser._flags._args and parser._flags._args[1] then
local tbl = { concat_one_letter_flags=true }
if parser._flags._args[1]._links["/d:"] then
table.insert(tbl, { hide=true, "/d" })
end
if parser._flags._args[1]._links["/D:"] then
local desc = parser._descriptions["/D:"]
table.insert(tbl, { "/D", desc[#desc] })
end
if tbl[1] then
parser:_addexflags(tbl)
end
end
end

require('help_parser').make('xcopy', '/?', nil, {concat=true}, closure)
Loading

0 comments on commit db9ed23

Please sign in to comment.