#!/usr/bin/env python3
'''
Simple script to use as an example for bash-completion
'''

import argparse
import sys

def gen_parser():
    'Creates and returns the ArgumentParser'
    parser = argparse.ArgumentParser()
    parser.add_argument('--version', action='store_true',
                        help='Show version and exit')
    parser.add_argument('--verbose', action='store_true',
                        help='Verbose messages')
    parser.add_argument('action', choices=('file', 'hostname'),
                        help='Which action to take')
    parser.add_argument('target',
                        help='''The target of the action. For the "file"
                            action, it is a file.  For the "hostname" action,
                            it is a hostname.
                            ''')
    return parser

def parse_args(arguments):
    'Parses command-line arguments.  Returns the result.'
    parser = gen_parser()
    return parser.parse_args(arguments)

def main(arguments):
    'Main logic here'
    args = parse_args(arguments)
    if args.version:
        print('foo version 1.0')
        return 0
    if args.verbose:
        print('Verbose is turned on')
        print('Action:', args.action)
        print('Target:', args.target)
    return 0

if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))

# vim: set ft=python:
