Git Product home page Git Product logo

face's People

Contributors

mahmoud avatar moshez avatar steven-cutting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

face's Issues

Unexpected error message when incorrect subcmd supplied

Issue

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.

Reproduce

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.

is face-20.1.1-py3-none-any.whl legit?

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?

sys.exit(0) alternative for helpers.py HelpHandler.default_help_func

What

Alternative to calling sys.exit() inside of HelpHandler.default_help_func method.

Why

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.

Alternative

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.

ArgumentArityError error

$ 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

New 20.1.1 release on pypi?

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?

multi-usage

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>

Help formatting cuts off multi-line doc strings

What

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.

Example

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.

Error message contains root cmd name not file name

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.