summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHervé Beraud <hberaud@redhat.com>2019-03-25 15:34:56 +0100
committerSorin Sbarnea <ssbarnea@redhat.com>2019-05-23 10:42:08 +0000
commit713aff286b124aeaa6b2bea3b0d70488b43de4a5 (patch)
tree74baad268c4857372f5cc74ae94738c62ba988c7
parent30926f6dbe05996009d407750acb5ea52a039e62 (diff)
downloadpbr-713aff286b124aeaa6b2bea3b0d70488b43de4a5.tar.gz
Set subparser argument required
When subparser argument is not provided by user argparse return an error message not really useful for user: 'Namespace' object has no attribute 'func' This is due to the fact that when we launch the pbr in cli mode the subparser argument is not mandatory (required) and directly we try to execute a undefined function. Set the subparser required is more helpful for users due to the fact that argparse display the helping message with the available sub-commands that users can use These changes provides the following output if the argument is not passed: usage: pbr [-h] [-v] {sha,info,freeze} ... main.py: error: too few arguments Change-Id: I7982f9d40cb0979ddb89d7bc53964167f8e4b269
-rw-r--r--pbr/cmd/main.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/pbr/cmd/main.py b/pbr/cmd/main.py
index 29cd61d..91ea384 100644
--- a/pbr/cmd/main.py
+++ b/pbr/cmd/main.py
@@ -86,7 +86,9 @@ def main():
version=str(pbr.version.VersionInfo('pbr')))
subparsers = parser.add_subparsers(
- title='commands', description='valid commands', help='additional help')
+ title='commands', description='valid commands', help='additional help',
+ dest='cmd')
+ subparsers.required = True
cmd_sha = subparsers.add_parser('sha', help='print sha of package')
cmd_sha.set_defaults(func=get_sha)