def main(arguments=None):
    argv = sys_argv if arguments is None else arguments

    argv = [a if isinstance(a, text_type) else a.decode('utf-8') for a in argv]

    version = client_version
    parser = argparse.ArgumentParser(
        add_help=False, formatter_class=HelpFormatter, usage='''
%(prog)s [--version] [--help] [--os-help] [--snet] [--verbose]
             [--debug] [--info] [--quiet] [--auth <auth_url>]
             [--auth-version <auth_version> |
                 --os-identity-api-version <auth_version> ]
             [--user <username>]
             [--key <api_key>] [--retries <num_retries>]
             [--os-username <auth-user-name>] [--os-password <auth-password>]
             [--os-user-id <auth-user-id>]
             [--os-user-domain-id <auth-user-domain-id>]
             [--os-user-domain-name <auth-user-domain-name>]
             [--os-tenant-id <auth-tenant-id>]
             [--os-tenant-name <auth-tenant-name>]
             [--os-project-id <auth-project-id>]
             [--os-project-name <auth-project-name>]
             [--os-project-domain-id <auth-project-domain-id>]
             [--os-project-domain-name <auth-project-domain-name>]
             [--os-auth-url <auth-url>] [--os-auth-token <auth-token>]
             [--os-storage-url <storage-url>] [--os-region-name <region-name>]
             [--os-service-type <service-type>]
             [--os-endpoint-type <endpoint-type>]
             [--os-cacert <ca-certificate>] [--insecure]
             [--no-ssl-compression]
             <subcommand> [--help] [<subcommand options>]

Command-line interface to the OpenStack Swift API.

Positional arguments:
  <subcommand>
    delete               Delete a container or objects within a container.
    download             Download objects from containers.
    list                 Lists the containers for the account or the objects
                         for a container.
    post                 Updates meta information for the account, container,
                         or object; creates containers if not present.
    stat                 Displays information for the account, container,
                         or object.
    upload               Uploads files or directories to the given container.
    capabilities         List cluster capabilities.
    tempurl              Create a temporary URL.
    auth                 Display auth related environment variables.

Examples:
  %(prog)s download --help

  %(prog)s -A https://auth.api.rackspacecloud.com/v1.0 \\
      -U user -K api_key stat -v

  %(prog)s --os-auth-url https://api.example.com/v2.0 \\
      --os-tenant-name tenant \\
      --os-username user --os-password password list

  %(prog)s --os-auth-url https://api.example.com/v3 --auth-version 3\\
      --os-project-name project1 --os-project-domain-name domain1 \\
      --os-username user --os-user-domain-name domain1 \\
      --os-password password list

  %(prog)s --os-auth-url https://api.example.com/v3 --auth-version 3\\
      --os-project-id 0123456789abcdef0123456789abcdef \\
      --os-user-id abcdef0123456789abcdef0123456789 \\
      --os-password password list

  %(prog)s --os-auth-token 6ee5eb33efad4e45ab46806eac010566 \\
      --os-storage-url https://10.1.5.2:8080/v1/AUTH_ced809b6a4baea7aeab61a \\
      list

  %(prog)s list --lh
'''.strip('\n'))
    parser.add_argument('--version', action='version',
                        version='python-swiftclient %s' % version)
    parser.add_argument('-h', '--help', action='store_true')

    default_auth_version = '1.0'
    for k in ('ST_AUTH_VERSION', 'OS_AUTH_VERSION', 'OS_IDENTITY_API_VERSION'):
        try:
            default_auth_version = environ[k]
            break
        except KeyError:
            pass

    parser.add_argument('--os-help', action='store_true', dest='os_help',
                        help='Show OpenStack authentication options.')
    parser.add_argument('--os_help', action='store_true',
                        help=argparse.SUPPRESS)
    parser.add_argument('-s', '--snet', action='store_true', dest='snet',
                        default=False, help='Use SERVICENET internal network.')
    parser.add_argument('-v', '--verbose', action='count', dest='verbose',
                        default=1, help='Print more info.')
    parser.add_argument('--debug', action='store_true', dest='debug',
                        default=False, help='Show the curl commands and '
                        'results of all http queries regardless of result '
                        'status.')
    parser.add_argument('--info', action='store_true', dest='info',
                        default=False, help='Show the curl commands and '
                        'results of all http queries which return an error.')
    parser.add_argument('-q', '--quiet', action='store_const', dest='verbose',
                        const=0, default=1, help='Suppress status output.')
    parser.add_argument('-A', '--auth', dest='auth',
                        default=environ.get('ST_AUTH'),
                        help='URL for obtaining an auth token.')
    parser.add_argument('-V', '--auth-version', '--os-identity-api-version',
                        dest='auth_version',
                        default=default_auth_version,
                        type=str,
                        help='Specify a version for authentication. '
                             'Defaults to env[ST_AUTH_VERSION], '
                             'env[OS_AUTH_VERSION], '
                             'env[OS_IDENTITY_API_VERSION] or 1.0.')
    parser.add_argument('-U', '--user', dest='user',
                        default=environ.get('ST_USER'),
                        help='User name for obtaining an auth token.')
    parser.add_argument('-K', '--key', dest='key',
                        default=environ.get('ST_KEY'),
                        help='Key for obtaining an auth token.')
    parser.add_argument('-R', '--retries', type=int, default=5, dest='retries',
                        help='The number of times to retry a failed '
                             'connection.')
    default_val = config_true_value(environ.get('SWIFTCLIENT_INSECURE'))
    parser.add_argument('--insecure',
                        action="store_true", dest="insecure",
                        default=default_val,
                        help='Allow swiftclient to access servers without '
                             'having to verify the SSL certificate. '
                             'Defaults to env[SWIFTCLIENT_INSECURE] '
                             '(set to \'true\' to enable).')
    parser.add_argument('--no-ssl-compression',
                        action='store_false', dest='ssl_compression',
                        default=True,
                        help='This option is deprecated and not used anymore. '
                             'SSL compression should be disabled by default '
                             'by the system SSL library.')

    os_grp = parser.add_argument_group("OpenStack authentication options")
    os_grp.add_argument('--os-username',
                        metavar='<auth-user-name>',
                        default=environ.get('OS_USERNAME'),
                        help='OpenStack username. Defaults to '
                             'env[OS_USERNAME].')
    os_grp.add_argument('--os_username',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-user-id',
                        metavar='<auth-user-id>',
                        default=environ.get('OS_USER_ID'),
                        help='OpenStack user ID. '
                        'Defaults to env[OS_USER_ID].')
    os_grp.add_argument('--os_user_id',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-user-domain-id',
                        metavar='<auth-user-domain-id>',
                        default=environ.get('OS_USER_DOMAIN_ID'),
                        help='OpenStack user domain ID. '
                        'Defaults to env[OS_USER_DOMAIN_ID].')
    os_grp.add_argument('--os_user_domain_id',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-user-domain-name',
                        metavar='<auth-user-domain-name>',
                        default=environ.get('OS_USER_DOMAIN_NAME'),
                        help='OpenStack user domain name. '
                             'Defaults to env[OS_USER_DOMAIN_NAME].')
    os_grp.add_argument('--os_user_domain_name',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-password',
                        metavar='<auth-password>',
                        default=environ.get('OS_PASSWORD'),
                        help='OpenStack password. Defaults to '
                             'env[OS_PASSWORD].')
    os_grp.add_argument('--os_password',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-tenant-id',
                        metavar='<auth-tenant-id>',
                        default=environ.get('OS_TENANT_ID'),
                        help='OpenStack tenant ID. '
                        'Defaults to env[OS_TENANT_ID].')
    os_grp.add_argument('--os_tenant_id',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-tenant-name',
                        metavar='<auth-tenant-name>',
                        default=environ.get('OS_TENANT_NAME'),
                        help='OpenStack tenant name. '
                             'Defaults to env[OS_TENANT_NAME].')
    os_grp.add_argument('--os_tenant_name',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-project-id',
                        metavar='<auth-project-id>',
                        default=environ.get('OS_PROJECT_ID'),
                        help='OpenStack project ID. '
                        'Defaults to env[OS_PROJECT_ID].')
    os_grp.add_argument('--os_project_id',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-project-name',
                        metavar='<auth-project-name>',
                        default=environ.get('OS_PROJECT_NAME'),
                        help='OpenStack project name. '
                             'Defaults to env[OS_PROJECT_NAME].')
    os_grp.add_argument('--os_project_name',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-project-domain-id',
                        metavar='<auth-project-domain-id>',
                        default=environ.get('OS_PROJECT_DOMAIN_ID'),
                        help='OpenStack project domain ID. '
                        'Defaults to env[OS_PROJECT_DOMAIN_ID].')
    os_grp.add_argument('--os_project_domain_id',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-project-domain-name',
                        metavar='<auth-project-domain-name>',
                        default=environ.get('OS_PROJECT_DOMAIN_NAME'),
                        help='OpenStack project domain name. '
                             'Defaults to env[OS_PROJECT_DOMAIN_NAME].')
    os_grp.add_argument('--os_project_domain_name',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-auth-url',
                        metavar='<auth-url>',
                        default=environ.get('OS_AUTH_URL'),
                        help='OpenStack auth URL. Defaults to '
                             'env[OS_AUTH_URL].')
    os_grp.add_argument('--os_auth_url',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-auth-token',
                        metavar='<auth-token>',
                        default=environ.get('OS_AUTH_TOKEN'),
                        help='OpenStack token. Defaults to '
                             'env[OS_AUTH_TOKEN]. Used with --os-storage-url '
                             'to bypass the usual username/password '
                             'authentication.')
    os_grp.add_argument('--os_auth_token',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-storage-url',
                        metavar='<storage-url>',
                        default=environ.get('OS_STORAGE_URL'),
                        help='OpenStack storage URL. '
                             'Defaults to env[OS_STORAGE_URL]. '
                             'Overrides the storage url returned during auth. '
                             'Will bypass authentication when used with '
                             '--os-auth-token.')
    os_grp.add_argument('--os_storage_url',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-region-name',
                        metavar='<region-name>',
                        default=environ.get('OS_REGION_NAME'),
                        help='OpenStack region name. '
                             'Defaults to env[OS_REGION_NAME].')
    os_grp.add_argument('--os_region_name',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-service-type',
                        metavar='<service-type>',
                        default=environ.get('OS_SERVICE_TYPE'),
                        help='OpenStack Service type. '
                             'Defaults to env[OS_SERVICE_TYPE].')
    os_grp.add_argument('--os_service_type',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-endpoint-type',
                        metavar='<endpoint-type>',
                        default=environ.get('OS_ENDPOINT_TYPE'),
                        help='OpenStack Endpoint type. '
                             'Defaults to env[OS_ENDPOINT_TYPE].')
    os_grp.add_argument('--os_endpoint_type',
                        help=argparse.SUPPRESS)
    os_grp.add_argument('--os-cacert',
                        metavar='<ca-certificate>',
                        default=environ.get('OS_CACERT'),
                        help='Specify a CA bundle file to use in verifying a '
                        'TLS (https) server certificate. '
                        'Defaults to env[OS_CACERT].')
    options, args = parse_args(parser, argv[1:], enforce_requires=False)

    if options.help or options.os_help:
        if options.help:
            parser._action_groups.pop()
        parser.print_help()
        exit()

    if not args or args[0] not in commands:
        parser.print_usage()
        if args:
            exit('no such command: %s' % args[0])
        exit()

    signal.signal(signal.SIGINT, immediate_exit)

    with OutputManager() as output:
        parser.usage = globals()['st_%s_help' % args[0]]
        try:
            globals()['st_%s' % args[0]](parser, argv[1:], output)
        except ClientException as err:
            output.error(str(err))
            trans_id = (err.http_response_headers or {}).get('X-Trans-Id')
            if trans_id:
                output.error("Failed Transaction ID: %s",
                             parse_header_string(trans_id))
        except (RequestException, socket.error) as err:
            output.error(str(err))

    if output.get_error_count() > 0:
        exit(1)
dataset/ETHPy150Open openstack/python-swiftclient/swiftclient/shell.py/main/original