Пример #1
0
 def setUp(self):
     self.index = InMemoryIndex({
         'command_names': {
             '': ['aws'],
             'aws': ['logs'],
             'aws.logs': ['tail'],
         },
         'arg_names': {
             '': {},
             'aws.logs': {
                 'tail': ['group_name'],
             },
         },
         'arg_data': {
             '': {},
             'aws.logs': {
                 'tail': {
                     'group_name': ('group_name', 'string', 'tail',
                                    'aws.logs.', None, True),
                 },
             }
         }
     })
     self.parser = parser.CLIParser(self.index)
     self.mock_client = mock.Mock()
     self.mock_create_client = mock.Mock()
     self.mock_create_client.create_client.return_value = self.mock_client
     self.completer = GroupNameCompleter(self.mock_create_client)
Пример #2
0
 def setUp(self):
     self.index = InMemoryIndex({
         'command_names': {
             '': ['aws'],
             'aws': ['ddb'],
             'aws.ddb': ['put', 'select'],
         },
         'arg_names': {
             '': {},
             'aws.ddb': {
                 'put': ['table_name'],
                 'select': ['table_name']
             },
         },
         'arg_data': {
             '': {},
             'aws.ddb': {
                 'put': {
                     'table_name': (
                         'table_name', 'string',
                         'put', 'aws.ddb.', None, True),
                 },
                 'select': {
                     'table_name': (
                         'table_name', 'string',
                         'select', 'aws.ddb.', None, True),
                 },
             }
         }
     })
     self.parser = parser.CLIParser(self.index)
     self.mock_client = mock.Mock()
     self.mock_create_client = mock.Mock()
     self.mock_create_client.create_client.return_value = self.mock_client
     self.completer = TableNameCompleter(self.mock_create_client)
Пример #3
0
def _assert_parses_to(command_line, expected):
    p = parser.CLIParser(SAMPLE_MODEL)
    result = p.parse(command_line)
    for key, value in vars(expected).items():
        actual = getattr(result, key)
        assert_equal(getattr(result, key), value,
                     '%r != %r for attribute: %r' % (actual, value, key))
Пример #4
0
 def setUp(self):
     self.index = InMemoryIndex({
         'command_names': {
             '': ['aws'],
             'aws': ['ec2', 'iam', 's3'],
             'aws.iam': ['delete-user-policy', 'delete-user'],
         },
         'arg_names': {
             '': {
                 'aws': ['region', 'endpoint-url'],
             },
             'aws.iam': {
                 'delete-user-policy': ['policy-name'],
                 'delete-user': ['user-name'],
             },
         },
         'arg_data': {
             '': {
                 'aws': {
                     'endpoint-url': ('endpoint-url', 'string',
                                      'aws', '', None, False),
                     'region': ('region', 'string', 'aws', '', None, False),
                 }
             },
             'aws.iam': {
                 'delete-user-policy': {
                     'policy-name': (
                         'policy-name', 'string',
                         'delete-user-policy', 'aws.iam.', None, False),
                 },
                 'delete-user': {
                     'user-name': (
                         'user-name', 'string',
                         'delete-user', 'aws.iam.', None, False),
                 }
             }
         }
     })
     key = (('aws', 'iam'), 'delete-user-policy', 'policy-name')
     self.completion_data = {
         key: {
             'completions': [{
                 "parameters": {},
                 "service": "iam",
                 "operation": "list_policies",
                 "jp_expr": "Policies[].PolicyName",
             }]
         }
     }
     self.parser = parser.CLIParser(self.index)
     self.mock_client = mock.Mock()
     self.mock_create_client = mock.Mock()
     self.mock_create_client.create_client.return_value = self.mock_client
     self.completion_lookup = FakeCompletionLookup(self.completion_data)
     self.completer = ServerSideCompleter(self.completion_lookup,
                                          self.mock_create_client)
Пример #5
0
def create_autocompleter(index_filename=None, custom_completers=None):
    if custom_completers is None:
        custom_completers = custom.get_custom_completers()
    if index_filename is None:
        index_filename = _get_index_filename()
    index = model.ModelIndex(index_filename)
    cli_parser = parser.CLIParser(index)
    completers = [
        basic.ModelIndexCompleter(index),
        serverside.create_server_side_completer(index_filename)
    ] + custom_completers
    cli_completer = completer.AutoCompleter(cli_parser, completers)
    return cli_completer
Пример #6
0
 def test_can_consume_zero_or_one_nargs(self):
     model = copy.deepcopy(SAMPLE_MODEL)
     nargs_one_or_more = '?'
     model.index['arg_data']['aws.ec2']['stop-instances']['foo-arg'] = (
         'foo-arg', 'string', 'stop-instances', 'aws.ec2',
         nargs_one_or_more, False)
     p = parser.CLIParser(model)
     self.assertEqual(
         p.parse('aws ec2 stop-instances --foo-arg --debug').
         parsed_params['foo-arg'], None)
     self.assertEqual(
         p.parse('aws ec2 stop-instances --foo-arg bar --debug').
         parsed_params['foo-arg'], 'bar')
Пример #7
0
def test_properties_of_unparsed_results():
    # The parser should never raise an exception.  If it can't
    # understand something it should still return a ParsedResult
    # with the parts it doesn't understand addded to the unparsed_items
    # attribute.  The ParsedResult should always have some basic invariants
    # we can verify which are called out in the tests below.
    # This test ensures that at every single slice of the full command_line
    # we always produce a sensical ParsedResult.
    command_line = ('aws ec2 stop-instances --instance-ids i-123 i-124 '
                    '--foo-arg value --debug --endpoint-url https://foo')
    cli_parser = parser.CLIParser(SAMPLE_MODEL)
    for i in range(1, len(command_line)):
        chunk = command_line[:i]
        yield _assert_parsed_properties, chunk, cli_parser
Пример #8
0
    def setUp(self):
        self.index = InMemoryIndex({
            'command_names': {
                '': ['aws'],
                'aws': ['ec2', 'ecs', 's3'],
                'aws.ec2': ['describe-instances'],
            },
            'arg_names': {
                '': {
                    'aws': ['region', 'endpoint-url'],
                },
                'aws.ec2': {
                    'describe-instances':
                    ['instance-ids', 'reserve', 'positional'],
                }
            },
            'arg_data': {
                '': {
                    'aws': {
                        'endpoint-url':
                        ('endpoint-url', 'string', 'aws', '', None, False),
                        'region': ('region', 'string', 'aws', '', None, False),
                    }
                },
                'aws.ec2': {
                    'describe-instances': {
                        'instance-ids':
                        ('instance-ids', 'string', 'describe-instances',
                         'aws.ec2.', None, False),
                        'reserve': ('reserve', 'string', 'describe-instances',
                                    'aws.ec2.', None, False),
                        'positional':
                        ('positional', 'string', 'describe-instances',
                         'aws.ec2.', None, True),
                    }
                }
            }
        })
        self.parser = parser.CLIParser(self.index)

        self.completer = basic.ModelIndexCompleter(self.index)
Пример #9
0
 def create_parser(self):
     return parser.CLIParser(SAMPLE_MODEL)