def test_registers_subparsers(self): profile_name = self.make_profile().keys()[0] parser = ArgumentParser() self.assertIsNone(parser._subparsers) api.register_api_commands(parser) self.assertIsNotNone(parser._subparsers) self.assertIsNotNone(parser.subparsers.choices[profile_name])
def test_registers_subparsers(self): profile_name = list(self.make_profile().keys())[0] parser = ArgumentParser() self.assertIsNone(parser._subparsers) api.register_api_commands(parser) self.assertIsNotNone(parser._subparsers) self.assertIsNotNone(parser.subparsers.choices[profile_name])
def prepare_parser(argv): """Create and populate an arguments parser for the maascli command.""" help_title, help_body = parse_docstring(api) parser = ArgumentParser( description=help_body, prog=argv[0], epilog="http://maas.ubuntu.com/") register_cli_commands(parser) api.register_api_commands(parser) return parser
def prepare_parser(argv): """Create and populate an arguments parser for the maascli command.""" help_title, help_body = parse_docstring(api) parser = ArgumentParser(description=help_body, prog=argv[0], epilog="http://maas.ubuntu.com/") register_cli_commands(parser) api.register_api_commands(parser) return parser
def prepare_parser(argv): """Create and populate an arguments parser for the maascli command.""" help_title, help_body = parse_docstring(api) parser = ArgumentParser(description=help_body, prog=os.path.basename(argv[0]), epilog="http://maas.io/") register_cli_commands(parser) api.register_api_commands(parser) parser.add_argument('--debug', action='store_true', default=False, help=argparse.SUPPRESS) return parser
def test_handlers_registered_using_correct_names(self): profile = self.make_profile() parser = ArgumentParser() api.register_api_commands(parser) for resource in list(profile.values())[0]["description"]["resources"]: for action in resource["auth"]["actions"]: # Profile names are matched as-is. [profile_name] = profile # Handler names are processed with handler_command_name before # being added to the argument parser tree. handler_name = handler_command_name(resource["name"]) # Action names are processed with safe_name before being added # to the argument parser tree. action_name = safe_name(action["name"]) # Parsing these names as command-line arguments yields an # options object. Its execute attribute is an instance of # Action (or a subclass thereof). options = parser.parse_args( (profile_name, handler_name, action_name)) self.assertIsInstance(options.execute, api.Action)
def test_handlers_registered_using_correct_names(self): profile = self.make_profile() parser = ArgumentParser() api.register_api_commands(parser) for resource in profile.values()[0]["description"]["resources"]: for action in resource["auth"]["actions"]: # Profile names are matched as-is. profile_name = profile.keys()[0] # Handler names are processed with handler_command_name before # being added to the argument parser tree. handler_name = handler_command_name(resource["name"]) # Action names are processed with safe_name before being added # to the argument parser tree. action_name = safe_name(action["name"]) # Parsing these names as command-line arguments yields an # options object. Its execute attribute is an instance of # Action (or a subclass thereof). options = parser.parse_args( (profile_name, handler_name, action_name)) self.assertIsInstance(options.execute, api.Action)