MCPcopy Create free account
hub / github.com/apple/axlearn / add_cmd_from_module

Method add_cmd_from_module

axlearn/cli/utils.py:153–172  ·  view source on GitHub ↗

Adds a command that invokes an existing absl script. Args: name: Command name. module: A string of the format `module_name`. kwargs: Default kwargs forwarded to `subparsers.add_parser`. Returns: The command.

(self, name: str, *, module: str, **kwargs)

Source from the content-addressed store, hash-verified

151 return cmd
152
153 def add_cmd_from_module(self, name: str, *, module: str, **kwargs) -> Command:
154 """Adds a command that invokes an existing absl script.
155
156 Args:
157 name: Command name.
158 module: A string of the format `module_name`.
159 kwargs: Default kwargs forwarded to `subparsers.add_parser`.
160
161 Returns:
162 The command.
163 """
164 # Note: always disable help here, since we want to leverage absl help.
165 cmd = self.add_cmd(name, add_help=False, **kwargs)
166 # Handle any added flags marked with `undefok=True`.
167 if hasattr(self.namespace, "undefok"):
168 argv = cmd.get_default("argv") or []
169 argv = _insert_flags(argv, [f"--undefok={self.namespace.undefok}"])
170 cmd.set_defaults(argv=argv)
171 cmd.set_defaults(command_type=CommandType.MODULE, module=module)
172 return cmd
173
174 def add_cmd_from_bash(self, name: str, *, command: str, **kwargs) -> Command:
175 """Adds a command that invokes a bash command.

Callers 2

add_cmd_groupFunction · 0.95
_parseFunction · 0.95

Calls 3

add_cmdMethod · 0.95
_insert_flagsFunction · 0.85
set_defaultsMethod · 0.45

Tested by 1

_parseFunction · 0.76