Skip to content

Commit

Permalink
Working to eliminate hard-coded provider references. Incorporating pa…
Browse files Browse the repository at this point in the history
…tch for zsh completion.
  • Loading branch information
garnaat committed Jan 25, 2013
1 parent 9338978 commit fea05c8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 30 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ For tcsh:

You should add this to your startup scripts to enable it for future sessions.

For zsh please refer to bin/zsh_complete.sh. Source that file:

$ source bin/zsh_complete.sh

For now the bash compatibility auto completion (bashcompinit) is used.
For further details please refer to the top of bin/zsh_complete.sh.


Getting Started
---------------
Before using aws-cli, you need to tell it about your AWS credentials. You
Expand Down
15 changes: 8 additions & 7 deletions awscli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@

__version__ = '0.4.5'

EnvironmentVariables = {
'profile': (None, 'AWS_DEFAULT_PROFILE'),
'region': ('region', 'AWS_DEFAULT_REGION'),
'data_path': ('data_path', 'AWS_DATA_PATH'),
'config_file': (None, 'AWS_CONFIG_FILE')
}

#
# Get our data path to be added to botocore's search path
#
Expand All @@ -38,3 +31,11 @@
path = os.path.expanduser(path)
awscli_data_path.append(path)
os.environ['AWS_DATA_PATH'] = ':'.join(awscli_data_path)


EnvironmentVariables = {
'profile': (None, 'AWS_DEFAULT_PROFILE', None),
'region': ('region', 'AWS_DEFAULT_REGION', None),
'data_path': ('data_path', 'AWS_DATA_PATH', None),
'config_file': (None, 'AWS_CONFIG_FILE', None)
}
20 changes: 8 additions & 12 deletions awscli/clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class CLIDriver(object):
'jsondoc': str,
'file': str}

def __init__(self, provider_name='aws'):
self.provider_name = provider_name
def __init__(self):
self.session = botocore.session.get_session(EnvironmentVariables)
self.session.user_agent_name = 'aws-cli'
self.session.user_agent_version = __version__
Expand Down Expand Up @@ -98,7 +97,9 @@ def create_main_parser(self):
if 'choices' in option_data:
choices = option_data['choices']
if not isinstance(choices, list):
choices = self.session.get_data(option_data['choices'])
provider = self.session.get_variable('provider')
choices_path = choices.format(provider=provider)
choices = self.session.get_data(choices_path)
if isinstance(choices, dict):
choices = list(choices.keys())
option_data['help'] = self.create_choice_help(choices)
Expand Down Expand Up @@ -281,17 +282,11 @@ def get_error_code_and_message(self, response):

def call(self, args):
try:
if self.args.region is not None:
self.region = self.args.region
elif self.session.get_config():
self.region = self.session.get_config().get('region', None)
if self.region is None:
msg = self.session.get_data('messages/NoRegionError')
raise ValueError(msg)
params = {}
self.build_call_parameters(args, params)
self.endpoint = self.service.get_endpoint(self.region,
self.endpoint = self.service.get_endpoint(self.args.region,
endpoint_url=self.args.endpoint_url)
self.endpoint.verify = not self.args.no_verify_ssl
http_response, response_data = self.operation.call(self.endpoint,
**params)
self.formatter(self.operation, response_data)
Expand Down Expand Up @@ -336,7 +331,8 @@ def main(self):
self.create_main_parser()
self.args, remaining = self.parser.parse_known_args()
if self.args.service_name == 'help':
get_help(self.session, provider='aws', style='cli')
provider = self.session.get_variable('provider')
get_help(self.session, provider=provider, style='cli')
sys.exit(0)
else:
if self.args.debug:
Expand Down
8 changes: 6 additions & 2 deletions awscli/data/cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
"help": "Override service's default URL with the given URL",
"metavar": "endpoint_url"
},
"--no-verify-ssl": {
"help": "Override default behavior of verifying SSL certificates",
"action": "store_true"
},
"--profile": {
"help": "Use a specific profile from your credential file",
"metavar": "profile_name"
},
"--region": {
"metavar": "region_name",
"choices": "aws/_regions"
"choices": "{provider}/_regions"
},
"--output": {
"choices": ["json", "text"],
Expand All @@ -27,7 +31,7 @@
"help": "Display the version of this tool"
},
"service_name": {
"choices": "aws/_services",
"choices": "{provider}/_services",
"metavar": "service_name"
}
}
Expand Down
15 changes: 9 additions & 6 deletions awscli/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ def do_parameters(self, operation):
msg = self.session.get_data('messages/Synopsis')
self.add_paragraph().write(self.style.h2(msg))
self.indent()
self.add_paragraph().write('aws %s %s' % (operation.service.cli_name,
operation.cli_name))
provider_name = self.session.get_variable('provider')
self.add_paragraph().write('%s %s %s' % (provider_name,
operation.service.cli_name,
operation.cli_name))
self.indent()
for param in required:
para = self.add_paragraph()
Expand Down Expand Up @@ -274,7 +276,7 @@ def do_service_names(self, provider_name):
self.get_current_paragraph().write(service_name)
self.style.end_li()

def do_options(self, options):
def do_options(self, options, provider_name):
self.add_paragraph().write(self.style.h2('Options'))
self.indent()
for option in options:
Expand All @@ -291,18 +293,19 @@ def do_options(self, options):
if 'choices' in option_data:
choices = option_data['choices']
if not isinstance(choices, list):
choices = self.session.get_data(choices)
choices_path = choices.format(provider=provider_name)
choices = self.session.get_data(choices_path)
for choice in sorted(choices):
self.style.start_li()
self.get_current_paragraph().write(choice)
self.style.end_li()
self.dedent()

def build(self, provider_name='aws'):
def build(self, provider_name):
cli = self.session.get_data('cli')
self.do_usage(cli['description'])
self.do_service_names(provider_name)
self.do_options(cli['options'])
self.do_options(cli['options'], provider_name)


def get_help(session, provider=None,
Expand Down
2 changes: 1 addition & 1 deletion bin/aws
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import awscli.clidriver


def main():
driver = awscli.clidriver.CLIDriver(provider_name='aws')
driver = awscli.clidriver.CLIDriver()
driver.main()


Expand Down
2 changes: 1 addition & 1 deletion bin/aws.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import awscli.clidriver


def main():
driver = awscli.clidriver.CLIDriver(provider_name='aws')
driver = awscli.clidriver.CLIDriver()
driver.main()


Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
author='Mitch Garnaat',
author_email='[email protected]',
url='http://aws.amazon.com/cli/',
scripts=['bin/aws', 'bin/aws_completer', 'bin/aws.cmd'],
scripts=['bin/aws', 'bin/aws.cmd',
'bin/aws_completer', 'bin/zsh_complete.sh'],
packages=packages,
package_data={'awscli': ['data/*.json']},
package_dir={'awscli': 'awscli'},
Expand Down

0 comments on commit fea05c8

Please sign in to comment.