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

Method add_flag

axlearn/cli/utils.py:189–210  ·  view source on GitHub ↗

Adds a flag to the command group. Args: name: Name of the flag. Should include "--". undefok: If True, the flag will be ignored if the invoked command does not support it, rather than throwing an error. default: Default flag value.

(
        self, name: str, undefok: bool = False, default: Optional[Any] = None, **kwargs
    )

Source from the content-addressed store, hash-verified

187 return cmd
188
189 def add_flag(
190 self, name: str, undefok: bool = False, default: Optional[Any] = None, **kwargs
191 ) -> Flag:
192 """Adds a flag to the command group.
193
194 Args:
195 name: Name of the flag. Should include "--".
196 undefok: If True, the flag will be ignored if the invoked command does not support it,
197 rather than throwing an error.
198 default: Default flag value.
199 kwargs: Default kwargs forwarded to `parser.add_argument`.
200
201 Returns:
202 The flag.
203 """
204 if undefok:
205 self.namespace.undefok = _add_to_csv(
206 getattr(self.namespace, "undefok", ""), name.removeprefix("--")
207 )
208 if default is not None:
209 self.namespace.defaults[name] = default
210 return self.parser.add_argument(name, default=default, **kwargs)
211
212 def parse_known_args(self) -> argparse_flags.argparse.Namespace:
213 """Parse argv.

Callers 2

add_cmd_groupFunction · 0.95
_parseFunction · 0.95

Calls 1

_add_to_csvFunction · 0.85

Tested by 1

_parseFunction · 0.76