TorchLean API

NN.API.CLI.Core

API CLI Helpers #

Small command-line parsers shared by examples, verification tools, and public facade helpers.

This module stays independent of tensors and runtime modules so lightweight artifact checkers can reuse the CLI surface without importing the full public API.

def NN.API.CLI.orThrow {α : Type} (x : Except String α) :
IO α

Lift a shared CLI parser result into IO.userError.

Instances For

    Strip at most one occurrence of a --key flag from an argument list.

    Accepted forms:

    • --key value
    • --key=value
    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.

      Instances For

        Parse a required string-valued flag and return the remaining arguments.

        Instances For

          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 takeFlagValueOnce: --key value and --key=value.

          Instances For

            Require a string-valued flag, accepting both --key value and --key=value.

            Instances For
              def NN.API.CLI.takeParsedFlagDefault {α : Type} (args : List String) (key default : String) (parse : StringExcept String α) :

              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.

              Instances For

                Return true when args contains --key value or --key=value.

                Instances For

                  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

                    Remove a no-value boolean flag once, returning whether it appeared.

                    Instances For

                      Drop the leading -- separator commonly used with lean --run.

                      Instances For

                        Return true when the argument list requests command help.

                        Instances For

                          Fail if there are any unconsumed CLI arguments.

                          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.

                            Instances For

                              Take one optional positional argument and fall back to default when it is absent.

                              Instances For

                                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

                                  Like takeFlagValueOnce, but parse the value as a Nat.

                                  Instances For

                                    Parse an optional natural-number flag and fall back to the provided default.

                                    Instances For

                                      Parse an optional natural-number flag, fall back to a default, and require that the selected value is strictly positive.

                                      Instances For

                                        Parse one ASCII decimal digit.

                                        Instances For

                                          Parse a nonempty string of ASCII decimal digits.

                                          Instances For

                                            Parse a signed decimal float literal.

                                            The primary path accepts the same numeric syntax as Lean.Json, including scientific notation. The fallback accepts the CLI-friendly decimal form 1..

                                            Instances For

                                              Like takeFlagValueOnce, but parse the value as a Float.

                                              Instances For

                                                Parse an optional floating-point flag and fall back to the provided default.

                                                Instances For

                                                  Parse a required floating-point flag and return the remaining arguments.

                                                  Instances For

                                                    Parse a CLI boolean value. Accepted spellings are true, false, 1, and 0.

                                                    Instances For

                                                      Like takeFlagValueOnce, but parse the value as a boolean.

                                                      Instances For

                                                        Parse an optional boolean-valued flag and fall back to the provided default.

                                                        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.

                                                          Instances For

                                                            Parse a bare-or-valued boolean flag and fall back to the provided default.

                                                            Instances For

                                                              Parse an optional floating-point flag, fall back to the provided default, and require that the selected value is strictly positive.

                                                              Instances For

                                                                Parse an optional floating-point flag, fall back to the provided default, and require that the selected value is nonnegative.

                                                                Instances For

                                                                  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.

                                                                  Instances For

                                                                    Parse a required path flag such as --data-file corpus.txt.

                                                                    The error message includes exeName when provided.

                                                                    Instances For

                                                                      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.

                                                                      Instances For

                                                                        Common training flags for epoch-oriented loader/tutorial commands: --epochs and --batch.

                                                                        • epochs : Nat

                                                                          Number of epochs to train for.

                                                                        • batch : Nat

                                                                          Batch size.

                                                                        Instances For
                                                                          def NN.API.CLI.takeEpochBatch (args : List String) (defaultEpochs defaultBatch : Nat) :

                                                                          Parse optional --epochs and --batch flags for the epoch-oriented tutorial helpers.

                                                                          Returns the parsed values (falling back to the provided defaults) and the remaining args.

                                                                          Instances For
                                                                            def NN.API.CLI.takePositiveEpochBatch (args : List String) (exeName : String) (defaultEpochs defaultBatch : Nat) :

                                                                            Parse optional --epochs and --batch flags for the epoch-oriented tutorial helpers, fall back to the provided defaults, and require that both selected values are strictly positive.

                                                                            Instances For

                                                                              Parse an optional --steps flag and fall back to the provided default.

                                                                              Instances For
                                                                                def NN.API.CLI.takeSeed (args : List String) (default : Nat := 0) :

                                                                                Parse an optional --seed flag (defaults to the provided value).

                                                                                Instances For