mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
Fix argparser (#5421)
fixed the issue caused by regression ## For community ⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment**
This commit is contained in:
parent
51a14c989d
commit
e03bda413a
3 changed files with 17 additions and 8 deletions
|
@ -77,3 +77,15 @@ def test_parser_hooking():
|
|||
"zsh",
|
||||
"bash",
|
||||
)
|
||||
|
||||
|
||||
def test_parser_default_func(mocker):
|
||||
import xonsh.xontribs as xx
|
||||
|
||||
alias = xx.XontribAlias()
|
||||
|
||||
def func():
|
||||
return True
|
||||
|
||||
mocker.patch.object(xx, "xontribs_list", func)
|
||||
assert alias([]) is True
|
||||
|
|
|
@ -208,10 +208,6 @@ def add_args(
|
|||
action.help += " (type: %(type)s)"
|
||||
|
||||
|
||||
def empty_help_func(_parser, _stdout):
|
||||
_parser.print_help(file=_stdout)
|
||||
|
||||
|
||||
def make_parser(
|
||||
func: tp.Union[tp.Callable, str],
|
||||
empty_help=False,
|
||||
|
@ -226,7 +222,7 @@ def make_parser(
|
|||
kwargs["epilog"] = doc.epilog
|
||||
parser = ArgParser(**kwargs)
|
||||
if empty_help:
|
||||
parser.set_defaults(**{_FUNC_NAME: empty_help_func})
|
||||
parser.default_command = "--help"
|
||||
return parser
|
||||
|
||||
|
||||
|
@ -410,6 +406,7 @@ def dispatch(parser: ap.ArgumentParser, args=None, lenient=False, **ns):
|
|||
ns["_parsed"] = parsed
|
||||
ns.update(vars(parsed))
|
||||
|
||||
if _FUNC_NAME in ns:
|
||||
func = ns[_FUNC_NAME]
|
||||
return _dispatch_func(func, ns)
|
||||
|
||||
|
|
|
@ -399,7 +399,7 @@ class XontribAlias(ArgParserAlias):
|
|||
parser.add_command(xontribs_load, prog="load")
|
||||
parser.add_command(xontribs_unload, prog="unload")
|
||||
parser.add_command(xontribs_reload, prog="reload")
|
||||
parser.add_command(xontribs_list, prog="list")
|
||||
parser.add_command(xontribs_list, prog="list", default=True)
|
||||
return parser
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue