mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Add trailing newline to output of complete functions
This commit is contained in:
@@ -18,7 +18,8 @@ _foo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _foo -o bashdefault -o default foo]=], parser:get_bash_complete())
|
complete -F _foo -o bashdefault -o default foo
|
||||||
|
]=], parser:get_bash_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for options with required argument", function()
|
it("generates correct completions for options with required argument", function()
|
||||||
@@ -45,7 +46,8 @@ _foo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _foo -o bashdefault -o default foo]=], parser:get_bash_complete())
|
complete -F _foo -o bashdefault -o default foo
|
||||||
|
]=], parser:get_bash_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for options with argument choices", function()
|
it("generates correct completions for options with argument choices", function()
|
||||||
@@ -73,7 +75,8 @@ _foo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _foo -o bashdefault -o default foo]=], parser:get_bash_complete())
|
complete -F _foo -o bashdefault -o default foo
|
||||||
|
]=], parser:get_bash_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for commands", function()
|
it("generates correct completions for commands", function()
|
||||||
@@ -109,7 +112,8 @@ _foo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _foo -o bashdefault -o default foo]=], parser:get_bash_complete())
|
complete -F _foo -o bashdefault -o default foo
|
||||||
|
]=], parser:get_bash_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for command options", function()
|
it("generates correct completions for command options", function()
|
||||||
@@ -149,7 +153,8 @@ _foo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _foo -o bashdefault -o default foo]=], parser:get_bash_complete())
|
complete -F _foo -o bashdefault -o default foo
|
||||||
|
]=], parser:get_bash_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates completions for help command argument", function()
|
it("generates completions for help command argument", function()
|
||||||
@@ -186,7 +191,8 @@ _foo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _foo -o bashdefault -o default foo]=], parser:get_bash_complete())
|
complete -F _foo -o bashdefault -o default foo
|
||||||
|
]=], parser:get_bash_complete())
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -194,7 +200,8 @@ complete -F _foo -o bashdefault -o default foo]=], parser:get_bash_complete())
|
|||||||
it("generates correct completions for help flag", function()
|
it("generates correct completions for help flag", function()
|
||||||
local parser = Parser "foo"
|
local parser = Parser "foo"
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
complete -c foo -s h -l help -d 'Show this help message and exit']], parser:get_fish_complete())
|
complete -c foo -s h -l help -d 'Show this help message and exit'
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for options with required argument", function()
|
it("generates correct completions for options with required argument", function()
|
||||||
@@ -202,7 +209,8 @@ complete -c foo -s h -l help -d 'Show this help message and exit']], parser:get_
|
|||||||
:add_help(false)
|
:add_help(false)
|
||||||
parser:option "--bar"
|
parser:option "--bar"
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
complete -c foo -l bar -r]], parser:get_fish_complete())
|
complete -c foo -l bar -r
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for options with argument choices", function()
|
it("generates correct completions for options with argument choices", function()
|
||||||
@@ -211,7 +219,8 @@ complete -c foo -l bar -r]], parser:get_fish_complete())
|
|||||||
parser:option "--format"
|
parser:option "--format"
|
||||||
:choices {"short", "medium", "full"}
|
:choices {"short", "medium", "full"}
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
complete -c foo -l format -xa 'short medium full']], parser:get_fish_complete())
|
complete -c foo -l format -xa 'short medium full'
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for commands", function()
|
it("generates correct completions for commands", function()
|
||||||
@@ -221,7 +230,8 @@ complete -c foo -l format -xa 'short medium full']], parser:get_fish_complete())
|
|||||||
:add_help(false)
|
:add_help(false)
|
||||||
:description "Install a rock."
|
:description "Install a rock."
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
complete -c foo -n '__fish_use_subcommand' -xa 'install' -d 'Install a rock']], parser:get_fish_complete())
|
complete -c foo -n '__fish_use_subcommand' -xa 'install' -d 'Install a rock'
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates correct completions for command options", function()
|
it("generates correct completions for command options", function()
|
||||||
@@ -232,7 +242,8 @@ complete -c foo -n '__fish_use_subcommand' -xa 'install' -d 'Install a rock']],
|
|||||||
install:flag "-v --verbose"
|
install:flag "-v --verbose"
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
complete -c foo -n '__fish_use_subcommand' -xa 'install'
|
complete -c foo -n '__fish_use_subcommand' -xa 'install'
|
||||||
complete -c foo -n '__fish_seen_subcommand_from install' -s v -l verbose]], parser:get_fish_complete())
|
complete -c foo -n '__fish_seen_subcommand_from install' -s v -l verbose
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("generates completions for help command argument", function()
|
it("generates completions for help command argument", function()
|
||||||
@@ -245,7 +256,8 @@ complete -c foo -n '__fish_seen_subcommand_from install' -s v -l verbose]], pars
|
|||||||
complete -c foo -n '__fish_seen_subcommand_from help' -xa 'help'
|
complete -c foo -n '__fish_seen_subcommand_from help' -xa 'help'
|
||||||
complete -c foo -n '__fish_seen_subcommand_from help' -xa 'install'
|
complete -c foo -n '__fish_seen_subcommand_from help' -xa 'install'
|
||||||
complete -c foo -n '__fish_use_subcommand' -xa 'help' -d 'Show help for commands'
|
complete -c foo -n '__fish_use_subcommand' -xa 'help' -d 'Show help for commands'
|
||||||
complete -c foo -n '__fish_use_subcommand' -xa 'install']], parser:get_fish_complete())
|
complete -c foo -n '__fish_use_subcommand' -xa 'install'
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("uses fist sentence of descriptions", function()
|
it("uses fist sentence of descriptions", function()
|
||||||
@@ -254,7 +266,8 @@ complete -c foo -n '__fish_use_subcommand' -xa 'install']], parser:get_fish_comp
|
|||||||
parser:option "--bar"
|
parser:option "--bar"
|
||||||
:description "A description with a .period. Another sentence."
|
:description "A description with a .period. Another sentence."
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
complete -c foo -l bar -r -d 'A description with a .period']], parser:get_fish_complete())
|
complete -c foo -l bar -r -d 'A description with a .period'
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("escapes backslashes and single quotes in descriptions", function()
|
it("escapes backslashes and single quotes in descriptions", function()
|
||||||
@@ -263,7 +276,8 @@ complete -c foo -l bar -r -d 'A description with a .period']], parser:get_fish_c
|
|||||||
parser:option "--bar"
|
parser:option "--bar"
|
||||||
:description "A description with illegal \\' characters."
|
:description "A description with illegal \\' characters."
|
||||||
assert.equal([[
|
assert.equal([[
|
||||||
complete -c foo -l bar -r -d 'A description with illegal \\\' characters']], parser:get_fish_complete())
|
complete -c foo -l bar -r -d 'A description with illegal \\\' characters'
|
||||||
|
]], parser:get_fish_complete())
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@@ -1095,7 +1095,7 @@ function Parser:add_complete(value)
|
|||||||
:args(1)
|
:args(1)
|
||||||
:choices {"bash", "zsh", "fish"}
|
:choices {"bash", "zsh", "fish"}
|
||||||
:action(function(_, _, shell)
|
:action(function(_, _, shell)
|
||||||
print(self["get_" .. shell .. "_complete"](self))
|
io.write(self["get_" .. shell .. "_complete"](self))
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -1224,7 +1224,8 @@ _%s() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _%s -o bashdefault -o default %s]=]):format(self._name, self._name))
|
complete -F _%s -o bashdefault -o default %s
|
||||||
|
]=]):format(self._name, self._name))
|
||||||
|
|
||||||
return table.concat(buf, "\n")
|
return table.concat(buf, "\n")
|
||||||
end
|
end
|
||||||
@@ -1302,7 +1303,7 @@ function Parser:get_fish_complete()
|
|||||||
|
|
||||||
self:_fish_complete_help(lines, prefix)
|
self:_fish_complete_help(lines, prefix)
|
||||||
|
|
||||||
return table.concat(lines, "\n")
|
return table.concat(lines, "\n") .. "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_tip(context, wrong_name)
|
local function get_tip(context, wrong_name)
|
||||||
|
Reference in New Issue
Block a user