Last active
          May 1, 2019 00:56 
        
      - 
      
 - 
        
Save mahmoud/8f60dd54c4729a71b5c3f7d0e64fe37a to your computer and use it in GitHub Desktop.  
    (based on years of argparse experience, also serves to demonstrate why argparse is not so good)
  
        
  
    
      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
    
  
  
    
  | def create_parser(): | |
| root_parser = ArgumentParser(description='article fetch operations') | |
| root_parser.add_argument('--list_home', help='list lookup directory') | |
| add_subparsers(root_parser.add_subparsers()) | |
| return root_parser | |
| def add_subparsers(subparsers): | |
| parser_list = subparsers.add_parser('list') | |
| parser_list.add_argument('target_list', nargs='?', | |
| help='Name of the list or list file') | |
| parser_list.set_defaults(func=get_list) | |
| ... | |
| def main(): | |
| parser = create_parser() | |
| args = parser.parse_args() | |
| kwargs = dict(args._get_kwargs()) | |
| args.func(**kwargs) | |
| if __name__ == '__main__': | |
| main() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment