TorchLean CLI Parser #
Pure command-line parsers shared by examples, verification tools, and application API helpers. The
definitions live directly under TorchLean.CLI.
This module stays independent of tensors and runtime modules so lightweight artifact checkers can reuse the CLI surface without importing the full public API.
Take an optional --key value from an argument list.
Accepted forms:
--key value--key=value
Duplicate occurrences are rejected. The returned argument list contains every unconsumed argument in its original order.
Instances For
Parse an optional string-valued flag and fall back to a provided default.
Use this when a command parser wants a concrete string immediately rather than an optional override.
Look up a string-valued flag without returning the remaining arguments.
This is useful for command shapes that support optional overrides but do not otherwise need a
left-to-right consuming parser. Accepted forms are the same as takeFlagValue?:
--key value and --key=value.
Instances For
Parse an optional string-valued flag, fall back to a provided default spelling when absent, and decode the selected spelling with a caller-supplied parser.
This is useful for enum-like CLI flags whose valid strings remain command-specific.
Remove every occurrence of a string-valued flag, accepting both --key value and --key=value.
This is for wrapper commands that own a flag locally and forward the remaining arguments to another tool. It deliberately does not reject duplicates; the wrapper's local parser decides whether a duplicated flag is an error.
Instances For
Return true when the argument list requests command help.
Instances For
Take at most one positional argument, leaving flags untouched.
This is useful for commands with a single optional artifact path plus named flags. A second positional argument is reported as an error instead of being silently ignored.
Normalize commands that accept either a positional path or a named path flag.
If --key / --key=... is already present, the argument list is returned unchanged. Otherwise the
first positional argument is rewritten to --key=<path>. If there is no positional path, the
provided default path is inserted.
Instances For
Remove a boolean flag that may be written either as a bare switch or with an explicit value.
Accepted forms:
--key--key=true--key=false--key true--key false
When --key is followed by a non-boolean token, the flag is treated as a bare switch and the next
token is left for the caller. Duplicate occurrences are rejected.
Parse an optional path flag and fall back to the provided default path.
Use this when an example parser wants a concrete path immediately instead of an optional override.
Parse two optional path flags that must appear together if either one is present.
This is useful for paired artifacts such as tokenizer vocab/merge files, where a single path is not meaningful on its own.