mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Show first sentence of description in option completion
This commit is contained in:
@@ -1120,6 +1120,11 @@ function Parser:add_help_command(value)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_short_description(element)
|
||||||
|
local short = element._description:match("^(.-)%.%s")
|
||||||
|
return short or element._description:match("^(.-)%.?$")
|
||||||
|
end
|
||||||
|
|
||||||
function Parser:get_bash_complete() print "not yet implemented" end
|
function Parser:get_bash_complete() print "not yet implemented" end
|
||||||
|
|
||||||
function Parser:get_zsh_complete() print "not yet implemented" end
|
function Parser:get_zsh_complete() print "not yet implemented" end
|
||||||
@@ -1131,8 +1136,13 @@ end
|
|||||||
function Parser:_fish_complete_help(lines, prefix)
|
function Parser:_fish_complete_help(lines, prefix)
|
||||||
for _, command in ipairs(self._commands) do
|
for _, command in ipairs(self._commands) do
|
||||||
for _, alias in ipairs(command._aliases) do
|
for _, alias in ipairs(command._aliases) do
|
||||||
local line = ("%s -n '__fish_use_subcommand' -xa '%s' -d '%s'")
|
local line = ("%s -n '__fish_use_subcommand' -xa '%s'"):format(prefix, alias)
|
||||||
:format(prefix, alias, fish_escape(command._description))
|
|
||||||
|
if command._description then
|
||||||
|
local description = fish_escape(get_short_description(command))
|
||||||
|
line = ("%s -d '%s'"):format(line, description)
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(lines, line)
|
table.insert(lines, line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1162,7 +1172,7 @@ function Parser:_fish_complete_help(lines, prefix)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if option._description then
|
if option._description then
|
||||||
local description = ("-d '%s'"):format(fish_escape(option._description))
|
local description = ("-d '%s'"):format(fish_escape(get_short_description(option)))
|
||||||
table.insert(parts, description)
|
table.insert(parts, description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user