Skip to content

Commit

Permalink
fix version information and the argument controlling it
Browse files Browse the repository at this point in the history
  • Loading branch information
snigdhasjg committed Nov 8, 2023
1 parent f88d607 commit 80b7ffe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
10 changes: 0 additions & 10 deletions aws_console/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
def aws_console():
args = open_console_arguments()

__show_version_if_requested(args)

creds, region_name = aws_session_credential(args.profile, args.region)
url = signin_url(creds, region_name)

Expand All @@ -22,15 +20,7 @@ def aws_console():
def aws_system_credential():
args = credential_process_arguments()

__show_version_if_requested(args)

if args.command == 'store':
store_aws_credential(args.account_id, args.username, args.access_key, args.secret_key)
elif args.command == 'get':
get_aws_credential(args.account_id, args.username, args.access_key, args.credential_process)


def __show_version_if_requested(args):
if args.version:
print(__version__)
exit(0)
21 changes: 12 additions & 9 deletions aws_console/input_output/cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os
import argparse

from importlib.metadata import version


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='store_true',
help="Display the version of this tool")
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 @@ -23,17 +25,18 @@ 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"))

parser = argparse.ArgumentParser(
description='AWS Credential Management CLI')

parser.add_argument('-v', '--version', action='store_true',
help="Display the version of this tool")
description='AWS Credential Management CLI', parents=[global_parser])

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

# Subparser for 'store' command
store_parser = subparsers.add_parser('store', help='Store AWS credentials')
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(
Expand All @@ -44,7 +47,7 @@ def credential_process_arguments():
'--secret-key', required=True, help='AWS secret key')

# Subparser for 'get' command
get_parser = subparsers.add_parser('get', help='Get AWS credentials')
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(
Expand Down

0 comments on commit 80b7ffe

Please sign in to comment.