From 7f6035c0c275bea68f5e29ce1ca31d9a7a87b078 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 31 Dec 2019 12:37:40 -0800 Subject: [PATCH] Improve argument wrapper --- amanuensis/__main__.py | 2 +- amanuensis/cli.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/amanuensis/__main__.py b/amanuensis/__main__.py index 513830d..41052e7 100644 --- a/amanuensis/__main__.py +++ b/amanuensis/__main__.py @@ -33,7 +33,7 @@ def get_parser(valid_commands): # whether their argument is an ArgumentParser. for name, func in valid_commands.items(): # Create the subparser. - cmd = subp.add_parser(name) + cmd = subp.add_parser(name, description=func.__doc__) # Delegate subparser setup. func(cmd) # Store function for later execution diff --git a/amanuensis/cli.py b/amanuensis/cli.py index 67c0465..ecce1f6 100644 --- a/amanuensis/cli.py +++ b/amanuensis/cli.py @@ -1,21 +1,28 @@ # Standard library imports from argparse import ArgumentParser as AP +from functools import wraps def add_argument(*args, **kwargs): def argument_adder(command): + @wraps(command) def augmented_command(cmd_args): if type(cmd_args) is AP: cmd_args.add_argument(*args, **kwargs) else: command(cmd_args) - augmented_command.__doc__ = command.__doc__ return augmented_command return argument_adder +def no_argument(command): + @wraps(command) + def augmented_command(cmd_args): + if type(cmd_args) is not AP: + command(cmd_args) + return augmented_command + @add_argument("--foo", action="store_true") def command_a(args): """a docstring""" print(args.foo) -