Skip to content

Commit 71be459

Browse files
committed
Moving rstgen here since it is quite specific to the CLI.
1 parent d686ba1 commit 71be459

4 files changed

Lines changed: 125 additions & 1 deletion

File tree

awscli/rstgen.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import sys
3+
import argparse
4+
from .clidriver import CLIDriver
5+
from bcdoc.mangen import gen_man
6+
7+
8+
def do_operation(session, args):
9+
service = session.get_service(args.service)
10+
operation = service.get_operation(args.operation)
11+
gen_man(session, operation=operation)
12+
13+
14+
def do_service(session, args):
15+
service = session.get_service(args.service)
16+
gen_man(session, service=service)
17+
18+
19+
def do_provider(session, args):
20+
cli_data = get_cli_data(session, provider_name=args.provider)
21+
gen_man(session, provider=args.provider, cli_data=cli_data)
22+
23+
24+
def get_cli_data(session, provider_name):
25+
cli_data = session.get_data('cli')
26+
for option in cli_data['options']:
27+
if option.startswith('--'):
28+
option_data = cli_data['options'][option]
29+
if 'choices' in option_data:
30+
choices = option_data['choices']
31+
if not isinstance(choices, list):
32+
choices_path = choices.format(provider=provider_name)
33+
choices = session.get_data(choices_path)
34+
option_data['choices'] = choices
35+
return cli_data
36+
37+
38+
def main():
39+
parser = argparse.ArgumentParser()
40+
parser.add_argument('--provider',
41+
help='Name of provider', required=True)
42+
parser.add_argument('--service',
43+
help='Name of service')
44+
parser.add_argument('--operation',
45+
help='Name of operation')
46+
args = parser.parse_args()
47+
driver = CLIDriver()
48+
if args.provider and args.service and args.operation:
49+
do_operation(driver.session, args)
50+
elif args.provider and args.service:
51+
do_service(driver.session, args)
52+
else:
53+
do_provider(driver.session, args)

bin/rstgen

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
# Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
# Licensed under the Apache License, Version 2.0 (the "License"). You
5+
# may not use this file except in compliance with the License. A copy of
6+
# the License is located at
7+
8+
# http://aws.amazon.com/apache2.0/
9+
10+
# or in the "license" file accompanying this file. This file is
11+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
# ANY KIND, either express or implied. See the License for the specific
13+
# language governing permissions and limitations under the License.
14+
import sys
15+
import awscli.rstgen
16+
17+
if __name__ == '__main__':
18+
sys.exit(awscli.rstgen.main())

bin/rstgen.cmd

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@echo OFF
2+
REM="""
3+
setlocal
4+
set PythonExe=
5+
set PythonExeFlags=
6+
7+
for %%i in (cmd bat exe) do (
8+
for %%j in (python.%%i) do (
9+
call :SetPythonExe "%%~$PATH:j"
10+
)
11+
)
12+
for /f "tokens=2 delims==" %%i in ('assoc .py') do (
13+
for /f "tokens=2 delims==" %%j in ('ftype %%i') do (
14+
for /f "tokens=1" %%k in ("%%j") do (
15+
call :SetPythonExe %%k
16+
)
17+
)
18+
)
19+
"%PythonExe%" -x %PythonExeFlags% "%~f0" %*
20+
goto :EOF
21+
22+
:SetPythonExe
23+
if not [%1]==[""] (
24+
if ["%PythonExe%"]==[""] (
25+
set PythonExe=%~1
26+
)
27+
)
28+
goto :EOF
29+
"""
30+
31+
# ===================================================
32+
# Python script starts here
33+
# ===================================================
34+
#!/usr/bin/env python
35+
# Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
36+
37+
# Licensed under the Apache License, Version 2.0 (the "License"). You
38+
# may not use this file except in compliance with the License. A copy of
39+
# the License is located at
40+
41+
# http://aws.amazon.com/apache2.0/
42+
43+
# or in the "license" file accompanying this file. This file is
44+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
45+
# ANY KIND, either express or implied. See the License for the specific
46+
# language governing permissions and limitations under the License.
47+
48+
import sys
49+
import awscli.rstgen
50+
51+
if __name__ == '__main__':
52+
sys.exit(awscli.rstgen.main())

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
author_email='[email protected]',
3737
url='http://aws.amazon.com/cli/',
3838
scripts=['bin/aws', 'bin/aws.cmd',
39-
'bin/aws_completer', 'bin/aws_zsh_completer.sh'],
39+
'bin/aws_completer', 'bin/aws_zsh_completer.sh',
40+
'bin/rstgen', 'bin/rstgen.cmd'],
4041
packages=packages,
4142
package_dir={'awscli': 'awscli'},
4243
install_requires=requires,

0 commit comments

Comments
 (0)