def __init__(self, impl_paths, path, release_track, construction_id, cli_generator, parser_group, parent_group=None, allow_empty=False): """Create a new command group. Args: impl_paths: [str], A list of file paths to the command implementation for this group. path: [str], A list of group names that got us down to this command group with respect to the CLI itself. This path should be used for things like error reporting when a specific element in the tree needs to be referenced. release_track: base.ReleaseTrack, The release track (ga, beta, alpha) that this command group is in. This will apply to all commands under it. construction_id: str, A unique identifier for the CLILoader that is being constructed. cli_generator: cli.CLILoader, The builder used to generate this CLI. parser_group: the current argparse parser, or None if this is the root command group. The root command group will allocate the initial top level argparse parser. parent_group: CommandGroup, The parent of this group. None if at the root. allow_empty: bool, True to allow creating this group as empty to start with. Raises: LayoutException: if the module has no sub groups or commands """ common_type = command_loading.LoadCommonType( impl_paths, path, release_track, construction_id, is_command=False) super(CommandGroup, self).__init__( common_type, path=path, release_track=release_track, cli_generator=cli_generator, allow_positional_args=False, parser_group=parser_group, parent_group=parent_group) self._construction_id = construction_id # find sub groups and commands self.groups = {} self.commands = {} self._groups_to_load = {} self._commands_to_load = {} self._unloadable_elements = set() group_infos, command_infos = command_loading.FindSubElements(impl_paths, path) self._groups_to_load.update(group_infos) self._commands_to_load.update(command_infos) if (not allow_empty and not self._groups_to_load and not self._commands_to_load): raise command_loading.LayoutException( 'Group {0} has no subgroups or commands'.format(self.dotted_name)) # Initialize the sub-parser so sub groups can be found. self.SubParser()
def testNoGroups(self): with self.assertRaisesRegex( command_loading.CommandLoadFailure, r'Problem loading foo.bar: Command groups cannot be implemented in ' r'yaml.'): command_loading.LoadCommonType(['dir/foo/bar.yaml'], ['foo', 'bar'], calliope_base.ReleaseTrack.GA, 'id', is_command=False) with self.assertRaisesRegex( command_loading.CommandLoadFailure, r'Problem loading foo.bar: Command groups cannot be implemented in ' r'yaml.'): command_loading.FindSubElements( ['dir/foo/bar.py', 'dir/foo/bar.yaml'], ['foo', 'bar'])