def get_argument_value_list(command_table, query, verbose=False): command_name = query['subcommand'] if command_name in command_table: command = command_table[command_name] argument_name = query['argument'] _, argument = get_argument(command, argument_name) if argument: if argument.choices: return argument.choices if argument.completer: values = run_argument_value_completer(command, argument, query['arguments']) if values is not None: return values if verbose: print('Completer not run ({} {})'.format( command_name, argument_name), file=stderr) elif verbose: print('Completions not found ({} {})'.format( command_name, argument_name), file=stderr) elif verbose and not [ a for a in GLOBAL_ARGUMENTS.values() if argument_name in a['options'] ]: print('Argument not found ({} {})'.format(command_name, argument_name), file=stderr) elif verbose: print('Command not found ({})'.format(command_name), file=stderr) return []
def test_global_argument(self): argument = GLOBAL_ARGUMENTS.get(TEST_GLOBAL_ARGUMENT) self.assertIsNotNone(argument) self.assertSequenceEqual(TEST_GLOBAL_ARGUMENT_OPTIONS, argument['options']) self.assertTrue(argument['help']) self.assertNotEqual(0, len(argument['choices']))
def get_global_argument_value_list(query, verbose=False): argument_name = query['argument'] argument = next((argument for argument in GLOBAL_ARGUMENTS.values() if argument_name in argument['options']), None) if argument: if 'choices' in argument: return argument['choices'] elif verbose: print('Completions not found ({})'.format(argument_name), file=stderr) return []
def get_global_argument_name_completions(query): arguments = query['arguments'] unused = [ argument for argument in GLOBAL_ARGUMENTS.values() if not [option for option in argument['options'] if option in arguments] ] return [{ 'name': option, 'kind': 'argument_name', 'detail': 'global', 'documentation': argument.get('help'), 'sortText': '30_' + option } for argument in unused for option in argument['options']]
def get_hover_text(group_index, command_table, command): subcommand = command['subcommand'] if 'argument' in command and subcommand in command_table: argument_name = command['argument'] argument = next( (argument for argument in get_arguments(command_table[subcommand]).values() if argument_name in argument.options_list), None) if argument: req = is_required(argument) return { 'paragraphs': [ '`' + ' '.join(argument.options_list) + '`' + ('*' if req else '') + ': ' + argument.type.settings.get('help') + ('\n\n*Required' if req else '') ] } argument = next((argument for argument in GLOBAL_ARGUMENTS.values() if argument_name in argument['options']), None) if argument: return { 'paragraphs': [ '`' + ' '.join(argument['options']) + '`: ' + argument['help'] ] } return help = get_help(subcommand) if help: short_summary = help.get('short-summary') if short_summary: paragraphs = [ '{1}\n\n`{0}`\n\n{2}'.format(subcommand, short_summary, help.get('long-summary', '')).strip() ] if subcommand in command_table: list = sorted( [ argument for argument in get_arguments( command_table[subcommand]).values() if argument.type.settings.get('help') != '==SUPPRESS==' ], key=lambda e: str(not is_required(e)) + e.options_list[0]) if list: paragraphs.append('Arguments\n' + '\n'.join([ '- `' + ' '.join(argument.options_list) + '`' + ('*' if is_required(argument) else '') + ': ' + (argument.type.settings.get('help') or '') for argument in list ]) + ('\n\n*Required' if is_required(list[0]) else '')) paragraphs.append('Global Arguments\n' + '\n'.join([ '- `' + ' '.join(argument['options']) + '`: ' + argument['help'] for argument in GLOBAL_ARGUMENTS.values() ])) elif subcommand in group_index: list = sorted(group_index[subcommand], key=lambda e: e['name']) groups = [ element for element in list if element['kind'] == 'group' ] if groups: paragraphs.append('Subgroups\n' + '\n'.join([ '- `' + element['name'] + '`: ' + get_short_summary(element.get('detail'), '-') for element in groups ])) commands = [ element for element in list if element['kind'] == 'command' ] if commands: paragraphs.append('Commands\n' + '\n'.join([ '- `' + element['name'] + '`: ' + get_short_summary(element.get('detail'), '-') for element in commands ])) examples = help.get('examples') if examples: paragraphs.append('Examples\n\n' + '\n\n'.join([ '{0}\n```azcli\n{1}\n```'.format(example['name'].strip(), example['text'].strip()) for example in examples ])) return {'paragraphs': paragraphs} return