Last active
February 23, 2022 00:59
-
-
Save natewalck/9139842 to your computer and use it in GitHub Desktop.
Sub arguments for argparse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import argparse | |
def main(): | |
parser = argparse.ArgumentParser(description="Runs the script") | |
subparsers = parser.add_subparsers(help='Specify secondary options') | |
secondary_parser = subparsers.add_parser('secondary', help='secondary options') | |
parser.add_argument("--primary", | |
help="Primary Arguments", | |
action="store_true") | |
secondary_parser.add_argument('-o', | |
'--one', | |
help='Sub-argument one', | |
action='store_true') | |
secondary_parser.add_argument('-t', | |
'--two', | |
help='Sub-argument two', | |
action='store_true') | |
args = parser.parse_args() | |
if __name__ == "__main__": | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./test.py --help | |
usage: test.py [-h] [--primary] {secondary} ... | |
Runs the script | |
positional arguments: | |
{secondary} Specify secondary options | |
secondary secondary options | |
optional arguments: | |
-h, --help show this help message and exit | |
--primary Primary Arguments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment