mahmoud / face Goto Github PK
View Code? Open in Web Editor NEW๐ฟ Straightforward CLI parsing and dispatching microframework
Home Page: https://python-face.readthedocs.io/
License: Other
๐ฟ Straightforward CLI parsing and dispatching microframework
Home Page: https://python-face.readthedocs.io/
License: Other
When an incorrect subcommand is supplied, the error says that there were unexpected positional arguments
.
Based on my understanding, positional arguments are not allowed at levels in which there exist further subcommands. So, I believe the error should say something along the lines of incorrect subcommand provided
.
from face import Command
cmd = Command(lambda: print("foo"), "foo")
subcmd = Command(lambda: print("bar"), "bar")
subcmd.add(Command(lambda: print("baz"), "baz"))
cmd.add(subcmd)
cmd.run(argv=["foo", "bar", "ba"]) # ba should be baz
Results in the following error:
error: foo bar: unexpected positional arguments: ['ba']
If you agree with the above, let me know and I can make it happen.
face 20.1.1 was released January 22, 2020 as a .tar.gz and a py2-none-any.whl. 6 hours ago, someone uploaded a py3-none-any.whl. I think it's pretty unusual to get a new whl download for a release 3 years old.
The py2 and py3 whls seem the same, except that the older py2 whl contains a test_parse.py
file the new py3 whl doesn't contain.
I don't see anything in the PR or issue trackers to suggest a face maintainer was uploading whls for older releases.
Is this new py3 whl release legit?
Alternative to calling sys.exit()
inside of HelpHandler.default_help_func
method.
It makes writing tests trickier. Any tests that run that method will fail. Ways of dealing with this feel like hacks.
Experience messing around with it in the shell is less than ideal. ipython does not exit, just throws error, but it is a little annoying.
Throw an HelpExitException
in place of sys.exit(0)
in HelpHandler.default_help_func
. Then catch HelpExitException
at the top level of the program. Call sys.exit(0)
in the except
block. Or just allow the program to exit naturally.
raise an error, helps disambiguate middlewares (maybe automatically turn it into middleware? probs too magical)
$ pprotect decrypt-domain -h
Traceback (most recent call last):
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/command.py", line 357, in run
prs_res = self.parse(argv=argv)
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/parser.py", line 774, in parse
parsed_posargs = prs.posargs.parse(posargs)
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/parser.py", line 486, in parse
% (arg_range_text, len_posargs))
face.errors.ArgumentArityError: too few arguments, expected 1 argument, got 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/bin/pprotect", line 8, in <module>
sys.exit(main())
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/pocket_protector/cli.py", line 201, in main
cmd.run(argv=argv) # exit behavior is handled by mw_exit_handler
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/command.py", line 365, in run
return inject(cmd.help_handler.func, kwargs)
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/sinter.py", line 59, in inject
return f(**kwargs)
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/helpers.py", line 429, in default_help_func
echo(self.formatter.get_help_text(command_, subcmds=subcmds_, program_name=cmd_))
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/helpers.py", line 249, in get_help_text
ret = [self.get_usage_line(parser, subcmds=subcmds, program_name=program_name)]
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/helpers.py", line 348, in get_usage_line
append(fmt_posargs_label(parser.posargs))
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/utils.py", line 133, in format_posargs_label
return get_cardinalized_args_label(posargspec.display.name, posargspec.min_count, posargspec.max_count)
File "/home/mahmoud/virtualenvs/tmp-a8562a6efb19e34/lib/python3.5/site-packages/face/utils.py", line 146, in get_cardinalized_args_label
return ' '.join([name] * min_count)
TypeError: sequence item 0: expected str instance, NoneType found
Hi,
I noticed a new Python 3 wheel build is uploaded to pypi for version 20.1.1. The Wheel is uploaded on pypi on Jan 19, 2023 with SHA256 hash: ca3a1d8b8b6aa8e61d62a300e9ee24e09c062aceda549e9a640128e4fa0f4559, yet there is no new release/tag on this project to match this. The hashes for the source distribution and Python 2 wheel release for 20.1.1 have not changed.
Could you please indicate if you uploaded this distribution and why?
It is not obvious where the canonical documentation lives
e.g.,
usage: git remote [-v | --verbose]
or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
or: git remote rename <old> <new>
or: git remote remove <name>
or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
or: git remote [-v | --verbose] show [-n] <name>
or: git remote prune [-n | --dry-run] <name>
If there is more than one line in a doc string of a function that is used to create a command. All but the first line are lost.
from face import Command
def multi_line_doc():
"""
Some multi line doc string. Some multi line doc string. Some multi line doc string. Some multi line doc string.
Some multi line doc string. Some multi line doc string. Some multi line doc string. Some multi line doc string.
"""
return
cmd = Command(multi_line_doc, 'cmd')
cmd.run(argv=['example.py', '--help'])
This results in:
Usage: example.py [FLAGS]
Some multi line doc string. Some multi line doc string. Some multi line doc string. Some multi line doc string.
Flags:
--help / -h show this help message and exit
Is this desired, or something that can be changed.
If it is desired, should an error be raised?
Let me know what you think and I can take care of it.
If I change a subparser, I want the parser to notice the change.
It is ok if it's explicit.
In error messages that display the path, should they make use of the root command name or file name? Or neither?
From what I can tell the end user never makes use off the root commands name, but they do make regular use of the file name. So for the end user it might result in less confusion/error if the file name is used.
This also affects the planned Did you mean?
feature, as they should probably display the same thing. Maybe to avoid this, this is why git's Did you mean?
only displays the final subcmd?
Example program:
#!/usr/bin/env python
from __future__ import print_function
import sys
from face import Command
def main():
cmd = Command(lambda: print("foo"), "foo")
subcmd = Command(lambda: print("bar"), "bar")
subcmd.add(Command(lambda: print("baz"), "baz"))
cmd.add(subcmd)
return cmd.run()
if __name__ == '__main__':
sys.exit(main())
If we place the above in a file named example
and call it with the following incorrect sub cmd.
$ ./example bar ba
We get the following error message:
error: foo bar: unexpected positional arguments: ['ba']
It is displaying the root commands name, foo
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.