Skip to content

Commit

Permalink
Refactor to extract common arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
snigdhasjg committed Nov 9, 2023
1 parent f52d47a commit 499f815
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions aws_console/input_output/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def open_console_arguments():
parser = argparse.ArgumentParser(
description="Open the AWS console in your web browser, using your AWS CLI credentials")

parser.add_argument(
'-v', '--version', action='version', help="Display the version of this tool", version=version("aws-console"))
parser.add_argument('-v', '--version', action='version',
help="Display the version of this tool", version=version("aws-console"))
parser.add_argument('-P', '--profile', default=os.getenv("AWS_PROFILE"),
help="The AWS profile to create the pre-signed URL with")
parser.add_argument('-R', '--region', default=os.getenv("AWS_REGION", os.getenv("AWS_DEFAULT_REGION")),
Expand All @@ -26,35 +26,33 @@ def open_console_arguments():

def credential_process_arguments():
global_parser = argparse.ArgumentParser(add_help=False)
global_parser.add_argument(
'-v', '--version', action='version', help="Display the version of this tool", version=version("aws-console"))
global_parser.add_argument('-v', '--version', action='version',
help="Display the version of this tool", version=version("aws-console"))

parser = argparse.ArgumentParser(
description='AWS Credential Management CLI', parents=[global_parser])

subparsers = parser.add_subparsers(
dest='command', required=True, help='Available commands')
subparsers = parser.add_subparsers(dest='command',
required=True, help='Available commands')

get_store_common_parser = argparse.ArgumentParser(add_help=False)
get_store_common_parser.add_argument('--account-id',
required=False, help='AWS Account ID for the name')
get_store_common_parser.add_argument('--username',
required=False, help='Username of a AWS user associated with the access key for the name')
get_store_common_parser.add_argument('--access-key',
required=True, help='AWS access key')

# Subparser for 'store' command
store_parser = subparsers.add_parser('store', help='Store AWS credentials', parents=[global_parser])
store_parser.add_argument(
'--account-id', required=False, help='AWS Account ID for the name')
store_parser.add_argument(
'--username', required=False, help='Username of a AWS user associated with the access key for the name')
store_parser.add_argument(
'--access-key', required=True, help='AWS access key')
store_parser.add_argument(
'--secret-key', required=True, help='AWS secret key')
store_parser = subparsers.add_parser('store',
help='Store AWS credentials', parents=[global_parser, get_store_common_parser])
store_parser.add_argument('--secret-key',
required=True, help='AWS secret key')

# Subparser for 'get' command
get_parser = subparsers.add_parser('get', help='Get AWS credentials', parents=[global_parser])
get_parser.add_argument(
'--account-id', required=False, help='AWS Account ID for the name')
get_parser.add_argument(
'--username', required=False, help='Username of a AWS user associated with the access key for the name')
get_parser.add_argument(
'--access-key', required=True, help='AWS access key')
get_parser.add_argument(
'--credential-process', action='store_true', help='Use credential process')
get_parser = subparsers.add_parser('get',
help='Get AWS credentials', parents=[global_parser, get_store_common_parser])
get_parser.add_argument('--credential-process',
action='store_true', help='Use credential process')

return parser.parse_args()

0 comments on commit 499f815

Please sign in to comment.