[feat] CLI-02/C-6: argparse-style args module#11
Merged
Conversation
Add an 'args' module that parses a script's own command-line arguments with a
surface that deliberately mirrors Python's argparse, so it reads familiarly:
load("args", "ArgumentParser")
p = ArgumentParser(description = "greet")
p.add_argument("--name", default = "World", help = "who")
p.add_argument("--count", type = int, default = 1)
p.add_argument("--shout", action = "store_true")
p.add_argument("file")
ns = p.parse_args() # parses argv[1:]
print(ns.name, ns.count, ns.shout, ns.file)
- ArgumentParser(prog, description) -> add_argument(name, type, default, help,
required, action='store_true') -> parse_args(argv=None) -> Namespace struct.
Plus format_help(). type accepts the Python builtins (int/float/str/bool) or
the equivalent string.
- argv[0] is the script name (or '-c'), like Python sys.argv; parse_args
defaults to argv[1:]. Supports '--name val', '--name=val', store_true flags,
positionals, the '--' terminator, and required checks; errors read
'prog: error: <msg>' and fail the run with a non-zero exit.
- Wired into mods.go (default module set) and classified CapPure in the
capability gate (pure parsing of the captured argv).
Table-driven tests cover parsing, types, errors, the argv[1:] default, the
terminator, and help. README documents it. Coverage 76.8%; Docker golang:1.22
green.
This was referenced Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLI-02 / C-6 β
args, a Pythonargparse-style argument parserPer the maintainer's call to make argument parsing "more like Python and easy to
understand", this adds an
argsmodule whose surface deliberately mirrorsargparse:Surface
ArgumentParser(prog, description)βadd_argument(name, type, default, help, required, action="store_true")βparse_args(argv=None)β aNamespacestruct (
ns.name). Plusformat_help()andargs.argv.typeaccepts the Python builtins (int/float/str/bool) or theequivalent string.
argv[0]is the script name (or-c), like Pythonsys.argv;parse_argsdefaults to
argv[1:]. Handles--name val,--name=val,store_trueflags, positionals, the
--terminator, and required checks.prog: error: <msg>and fail the run with a non-zero exit.Wiring
Added to the default module set (
mods.go) and classifiedCapPurein thecapability gate (pure parsing of the captured argv β loads in every tier).
Table-driven tests cover parsing / types / errors / the
argv[1:]default / the--terminator / help. README documents it. Coverage 76.8% (β₯ 65); Dockergolang:1.22green.Part of CLI-02 (STAR-19). Remaining there: stdin/pipe streaming (C-3).