|
| 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) |
0 commit comments