Correct argparse behavior
- disallow zero args - print help message if no commands given
This commit is contained in:
@@ -108,7 +108,7 @@ class bam_utils:
|
||||
stream=True,
|
||||
)
|
||||
|
||||
if r.status_code not in {200,}:
|
||||
if r.status_code not in {200, }:
|
||||
# TODO(cam), make into reusable function?
|
||||
print("Error %d:\n%s" % (r.status_code, next(r.iter_content(chunk_size=1024)).decode('utf-8')))
|
||||
return
|
||||
@@ -186,7 +186,7 @@ def subcommand_status_cb(args):
|
||||
def create_argparse_checkout(subparsers):
|
||||
subparse = subparsers.add_parser("checkout", aliases=("co",))
|
||||
subparse.add_argument(
|
||||
"paths", nargs="*", help="Path(s) to operate on",
|
||||
"paths", nargs="+", help="Path(s) to operate on",
|
||||
)
|
||||
subparse.set_defaults(func=subcommand_checkout_cb)
|
||||
|
||||
@@ -199,7 +199,7 @@ def create_argparse_commit(subparsers):
|
||||
help="Commit message",
|
||||
)
|
||||
subparse.add_argument(
|
||||
"paths", nargs="*", help="paths to commit",
|
||||
"paths", nargs="+", help="paths to commit",
|
||||
)
|
||||
|
||||
subparse.set_defaults(func=subcommand_commit_cb)
|
||||
@@ -208,7 +208,7 @@ def create_argparse_commit(subparsers):
|
||||
def create_argparse_update(subparsers):
|
||||
subparse = subparsers.add_parser("update", aliases=("up",))
|
||||
subparse.add_argument(
|
||||
"paths", nargs="*", help="Path(s) to operate on",
|
||||
"paths", nargs="+", help="Path(s) to operate on",
|
||||
)
|
||||
subparse.set_defaults(func=subcommand_update_cb)
|
||||
|
||||
@@ -216,7 +216,7 @@ def create_argparse_update(subparsers):
|
||||
def create_argparse_revert(subparsers):
|
||||
subparse = subparsers.add_parser("update", aliases=("up",))
|
||||
subparse.add_argument(
|
||||
"paths", nargs="*", help="Path(s) to operate on",
|
||||
"paths", nargs="+", help="Path(s) to operate on",
|
||||
)
|
||||
subparse.set_defaults(func=subcommand_revert_cb)
|
||||
|
||||
@@ -225,7 +225,7 @@ def create_argparse_revert(subparsers):
|
||||
def create_argparse_status(subparsers):
|
||||
subparse = subparsers.add_parser("status", aliases=("st",))
|
||||
subparse.add_argument(
|
||||
"paths", nargs="*", help="Path(s) to operate on",
|
||||
"paths", nargs="+", help="Path(s) to operate on",
|
||||
)
|
||||
subparse.set_defaults(func=subcommand_status_cb)
|
||||
|
||||
@@ -233,7 +233,7 @@ def create_argparse_status(subparsers):
|
||||
def create_argparse_list(subparsers):
|
||||
subparse = subparsers.add_parser("list", aliases=("ls",))
|
||||
subparse.add_argument(
|
||||
"paths", nargs="*", help="Path(s) to operate on",
|
||||
"paths", nargs="+", help="Path(s) to operate on",
|
||||
)
|
||||
subparse.set_defaults(func=subcommand_list_cb)
|
||||
|
||||
@@ -273,6 +273,10 @@ def main():
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
# call subparser callback
|
||||
if not hasattr(args, "func"):
|
||||
parser.print_help()
|
||||
return
|
||||
|
||||
args.func(args)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user