def get_argument_name_completions(command_table, query): command_name = query['subcommand'] command = command_table[command_name] arguments = query['arguments'] unused = { name: argument for name, argument in get_arguments(command).items() if not [ option for option in argument.options_list if option in arguments ] and argument.type.settings.get('help') != '==SUPPRESS==' } defaults = get_defaults(unused) return [{ 'name': option, 'kind': 'argument_name', 'required': is_required(argument), 'default': not not defaults.get(name), 'detail': 'required' if is_required(argument) and not defaults.get(name) else None, 'documentation': argument.type.settings.get('help'), 'sortText': ('10_' if is_required(argument) and not defaults.get(name) else '20_') + option } for name, argument in unused.items() for option in argument.options_list]
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
def test_is_linux_optional(self): command = self.command_table.get('appservice plan create') self.assertIsNotNone(command) self.assertFalse(is_required(get_arguments(command).get('is_linux')))
def test_required_argument(self): command = self.command_table.get(TEST_COMMAND) self.assertIsNotNone(command) self.assertTrue(is_required(get_arguments(command).get(TEST_ARGUMENT))) self.assertFalse( is_required(get_arguments(command).get(TEST_OPTIONAL_ARGUMENT)))