src/lsi/lsi.py
def _get_args():
    """Parse command-line arguments."""
    parser = argparse.ArgumentParser(description='List EC2 instances')
    parser.add_argument('-l', '--latest', action='store_true', default=False,
                        help='Query AWS for latest instances')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Print version and exit')
    parser.add_argument('--refresh-only', action='store_true', default=False,
                        help='Refresh cache and exit')
    parser.add_argument('--host', help='Specific host to list',
                        default=None)
    parser.add_argument('-s', '--ssh', action='store_true',
                        help='SSH to instance', default=False)
    parser.add_argument('-i', '--identity-file', help='SSH identify file',
                        default=None)
    parser.add_argument('-u', '--username', default=None,
                        help='Log in as this user')
    parser.add_argument('filters', nargs='*',
                        help='Text filters for output lines')
    parser.add_argument('-v', '--exclude', nargs='+',
                        help='Exclude results that match these')
    parser.add_argument('-c', '--command', type=str,
                        help='Command to run on matching instance(s)')
    parser.add_argument('-y', '--no-prompt', action='store_true', default=False,
                        help="Don't ask for confirmation before running a "
                             "command")
    parser.add_argument('-p', '--profile', type=str,
                        help='Profile to use (defined in ~/.lsi)')
    parser.add_argument('--show', nargs='+', default=None,
                        help='Instance attributes to show')
    parser.add_argument('--only', nargs='+', default=None,
                        help='Show ONLY these instance attributes')
    parser.add_argument('--sep', type=str, default=None,
                        help='Simple output with given separator')
    parser.add_argument('--sort-by', type=str, default="name",
                        help='What to sort list by')
    parser.add_argument('-L', '--limit', type=int, default=None,
                        help='Show at most this many entries')
    parser.add_argument('--attributes', action='store_true',
                        help='Show all available attributes')
    parser.add_argument('--get', nargs=2, default=None,
                        help='Get files from matching instances, must be '
                             'followed by the source and destination filenames')
    parser.add_argument('--put', nargs=2, default=None,
                        help='Put a local file on matching instances, must be '
                             'followed by the source and destination filenames')
    parser.add_argument('-t', '--tunnel', default=None,
                        help='Connect via the tunneled host.')
    parser.add_argument("-r", "--random", action="store_true", default=False,
                        help="Choose a random instance from within results.")
    parser.add_argument("-n", "--num", type=int, default=None,
                        help="Choose the given number from within results.")
    args = parser.parse_args()
    if args.exclude is None:
        args.exclude = []
    # Presumably, if someone is sorting by something, they want to show that
    # thing...
    if args.sort_by is not None:
        args.show = (args.show or []) + [args.sort_by]
    return args
def _get_args():
    """Parse command-line arguments."""
    parser = argparse.ArgumentParser(description='List EC2 instances')
    parser.add_argument('-l', '--latest', action='store_true', default=False,
                        help='Query AWS for latest instances')
    parser.add_argument('--version', action='store_true', default=False,
                        help='Print version and exit')
    parser.add_argument('--refresh-only', action='store_true', default=False,
                        help='Refresh cache and exit')
    parser.add_argument('--host', help='Specific host to list',
                        default=None)
    parser.add_argument('-s', '--ssh', action='store_true',
                        help='SSH to instance', default=False)
    parser.add_argument('-i', '--identity-file', help='SSH identify file',
                        default=None)
    parser.add_argument('-u', '--username', default=None,
                        help='Log in as this user')
    parser.add_argument('filters', nargs='*',
                        help='Text filters for output lines')
    parser.add_argument('-v', '--exclude', nargs='+',
                        help='Exclude results that match these')
    parser.add_argument('-c', '--command', type=str,
                        help='Command to run on matching instance(s)')
    parser.add_argument('-y', '--no-prompt', action='store_true', default=False,
                        help="Don't ask for confirmation before running a "
                             "command")
    parser.add_argument('-p', '--profile', type=str,
                        help='Profile to use (defined in ~/.lsi)')
    parser.add_argument('--show', nargs='+', default=None,
                        help='Instance attributes to show')
    parser.add_argument('--only', nargs='+', default=None,
                        help='Show ONLY these instance attributes')
    parser.add_argument('--sep', type=str, default=None,
                        help='Simple output with given separator')
    parser.add_argument('--sort-by', type=str, default="name",
                        help='What to sort list by')
    parser.add_argument('-L', '--limit', type=int, default=None,
                        help='Show at most this many entries')
    parser.add_argument('--attributes', action='store_true',
                        help='Show all available attributes')
    parser.add_argument('--get', nargs=2, default=None,
                        help='Get files from matching instances, must be '
                             'followed by the source and destination filenames')
    parser.add_argument('--put', nargs=2, default=None,
                        help='Put a local file on matching instances, must be '
                             'followed by the source and destination filenames')
    parser.add_argument('-t', '--tunnel', default=None,
                        help='Connect via the tunneled host.')
    parser.add_argument("-r", "--random", action="store_true", default=False,
                        help="Choose a random instance from within results.")
    parser.add_argument("-n", "--num", type=int, default=None,
                        help="Choose the given number from within results.")
    args = parser.parse_args()
    if args.exclude is None:
        args.exclude = []
    # Presumably, if someone is sorting by something, they want to show that
    # thing...
    if args.sort_by is not None:
        args.show = (args.show or []) + [args.sort_by]
    return args
def _get_args ( ) : parser = argparse . ArgumentParser ( description = 'List EC2 instances' ) parser . add_argument ( '-l' , '--latest' , action = 'store_true' , default = False , help = 'Query AWS for latest instances' ) parser . add_argument ( '--version' , action = 'store_true' , default = False , help = 'Print version and exit' ) parser . add_argument ( '--refresh-only' , action = 'store_true' , default = False , help = 'Refresh cache and exit' ) parser . add_argument ( '--host' , help = 'Specific host to list' , default = None ) parser . add_argument ( '-s' , '--ssh' , action = 'store_true' , help = 'SSH to instance' , default = False ) parser . add_argument ( '-i' , '--identity-file' , help = 'SSH identify file' , default = None ) parser . add_argument ( '-u' , '--username' , default = None , help = 'Log in as this user' ) parser . add_argument ( 'filters' , nargs = '*' , help = 'Text filters for output lines' ) parser . add_argument ( '-v' , '--exclude' , nargs = '+' , help = 'Exclude results that match these' ) parser . add_argument ( '-c' , '--command' , type = str , help = 'Command to run on matching instance(s)' ) parser . add_argument ( '-y' , '--no-prompt' , action = 'store_true' , default = False , help = "Don't ask for confirmation before running a " "command" ) parser . add_argument ( '-p' , '--profile' , type = str , help = 'Profile to use (defined in ~/.lsi)' ) parser . add_argument ( '--show' , nargs = '+' , default = None , help = 'Instance attributes to show' ) parser . add_argument ( '--only' , nargs = '+' , default = None , help = 'Show ONLY these instance attributes' ) parser . add_argument ( '--sep' , type = str , default = None , help = 'Simple output with given separator' ) parser . add_argument ( '--sort-by' , type = str , default = "name" , help = 'What to sort list by' ) parser . add_argument ( '-L' , '--limit' , type = int , default = None , help = 'Show at most this many entries' ) parser . add_argument ( '--attributes' , action = 'store_true' , help = 'Show all available attributes' ) parser . add_argument ( '--get' , nargs = 2 , default = None , help = 'Get files from matching instances, must be ' 'followed by the source and destination filenames' ) parser . add_argument ( '--put' , nargs = 2 , default = None , help = 'Put a local file on matching instances, must be ' 'followed by the source and destination filenames' ) parser . add_argument ( '-t' , '--tunnel' , default = None , help = 'Connect via the tunneled host.' ) parser . add_argument ( "-r" , "--random" , action = "store_true" , default = False , help = "Choose a random instance from within results." ) parser . add_argument ( "-n" , "--num" , type = int , default = None , help = "Choose the given number from within results." ) args = parser . parse_args ( ) if args . exclude is None : args . exclude = [ ] # Presumably, if someone is sorting by something, they want to show that # thing... if args . sort_by is not None : args . show = ( args . show or [ ] ) + [ args . sort_by ] return args
Parse command-line arguments.
Parse command - line arguments .