Advertisement
furas

Python - argparse

Jun 3rd, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. import argparse
  2. import sys
  3.  
  4. def main():
  5.     parseit = argparse.ArgumentParser(description="Log into any of FB, Twitter, Gmail, and Yahoo using <username> and <password>")
  6.     root_group = parseit.add_argument_group()
  7.  
  8.     creds_group = root_group.add_mutually_exclusive_group(required=True)
  9.     creds_group.add_argument('-b','--ball', action='store_false',help="Log into all accounts")
  10.    
  11.     file_group = creds_group.add_argument_group()
  12.     file_group.add_argument('-i','--file', type=file, help="Log in with credentials in file with format as 'username:password'")
  13.  
  14.     inline_creds = creds_group.add_argument_group()
  15.     inline_creds.add_argument("username",help="Username to log in as")
  16.     inline_creds.add_argument("password",help="Password to log in with")
  17.    
  18.     site_group = root_group.add_mutually_exclusive_group()
  19.     site_group.add_argument('-a','--all', action='store_false',help="Log into all accounts")
  20.    
  21.     sites_avail = site_group.add_argument_group("Site Set","none")
  22.     sites_avail.add_argument('-t','--twitter', action='store_false',help="Log into Twitter")
  23.     sites_avail.add_argument('-f','--facebook', action='store_false',help="Log into Facebook")
  24.     sites_avail.add_argument('-y','--yahoo', action='store_false',help="Log into Yahoo")
  25.     sites_avail.add_argument('-g','--gmail', action='store_false',help="Log into Gmail")
  26.     parseit.print_help()
  27.  
  28.     """
  29.    I get this error IndexError: list index out of range
  30.    I found this but the goals of the op is different than mine: https://stackoverflow.com/questions/30499648/python-mutually-exclusive-arguments-complains-about-action-index
  31.    """
  32. if __name__ == "__main__":
  33.         main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement