o-family oden
おでん oden — a hotpot of skewered ingredients
Subcommand dispatch for Go CLIs: a bin's inline commands and every <bin>-<sub> executable on PATH, in one table, resolved by name, alias or unique prefix.
libraryv0.1.1earlyGo 1.26 or newer
The hello example: its help listing inline and external commands, a unique prefix running a command, an ambiguous prefix listing its candidates, a did-you-mean suggestion and a handler reading stdin
overview
What it is
The lowest layer for extensible, subcommand-driven CLI tools in Go: a bin's inline commands merged with third-party executables on PATH, git- and hiiro-style. No dependencies outside the standard library, no application knowledge.
It is the outer shell of ochazuke apps, of matomeru's mtm and of the family's o-* tools. The family root bin, o, lives in this repository too: o proj, o ai and o inv are just o-proj, o-ai and o-inventory on PATH.
install
go get github.com/unixsuperhero/oden@latest
go build -o ~/bin/o ./cmd/o # from a checkout
func main() {
app := oden.New("hello", os.Args[1:], oden.WithBuiltins())
app.Cmd("greet", "say hello", func(c *oden.Ctx) error {
return c.Printf("hello, %s\n", c.Arg(0, "world"))
}, "hi")
os.Exit(oden.Report(os.Stderr, "hello", app.Run(context.Background())))
}
features
What it does
01 / 06
Commands are names on PATH
Any executable named
<bin>-<sub>on PATH is the commandsubofbin: puthello-weatheron PATH andhello weatherruns it, with no change to the bin.02 / 06
Unique-prefix resolution
Every word resolves by exact name or alias, else by unique prefix. Descendants never make a prefix ambiguous:
<other>-...candidates are children of<other>.03 / 06
Nothing hidden silently
Inline names beat externals, externals beat aliases, and every losing claim stays on the winner as a
shadows ...line in help and incommands --json.04 / 06
Merged command groups
An inline group and an external
<bin>-NAMEon PATH are one group: their subcommands resolve together, each listed with its source.05 / 06
Handlers and input
Cmdregisters a handler with arguments, context and streams.Input,TextandLinesread files and stdin in order, with-for stdin.06 / 06
Standard library only
No dependencies, injectable PATH and file system, builtins for help,
commands,whichand did-you-mean suggestions.
$ hello gr Ada
hello, Ada
$ hello wea Tokyo
weather in Tokyo: sunny, 21C
$ hello h
hello: "h" is ambiguous; did you mean one of these?
greet, hi (inline) say hello
help, -h, --help (inline) list the commands by audience
read more