neithere / argh

An argparse wrapper that doesn't make you say "argh" each time you deal with it.
http://argh.rtfd.org
GNU Lesser General Public License v3.0
369 stars 56 forks source link

Fix bug with skip_unknown_args=True #134

Closed Gidgidonihah closed 1 year ago

Gidgidonihah commented 5 years ago

Passing skip_unknown_args=True to the parser only ever showed the usage message.

The problem is that parser.parse_known_args() (ArgumentParser.parse_known_args) returns a tuple (namespace, remainder) instead of just a namespace object like parser.parse_args. Once you pass this to _get_function_from_namespace_obj it gets confused.

The unit test was expecting to only ever show the usage message when skipping unknown args.

The remaining unknown args are stored on the namespace as _unkown_args, so it's at least accessible (if we use @expects_obj)

import argh
parser = argh.ArghParser()

@argh.arg('a')
@argh.expects_obj
def foo(args):
    print 'foo args', args

parser.add_commands([foo, bar])
parser.dispatch(skip_unknown_args=True)

This uses and supersedes #86

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.2%) to 93.131% when pulling 33c25351c064b70b69f1a90583eb3da7b32d7cd9 on CruxConnect:master into dcd3253f2994400a6a58a700c118c53765bc50a4 on neithere:master.

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.2%) to 93.131% when pulling 33c25351c064b70b69f1a90583eb3da7b32d7cd9 on CruxConnect:master into dcd3253f2994400a6a58a700c118c53765bc50a4 on neithere:master.