o-family

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

examples/hellorec
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

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
go get github.com/unixsuperhero/oden@latest
o root bin
go build -o ~/bin/o ./cmd/o   # from a checkout
hello/main.gogo
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

  1. 01 / 06

    Commands are names on PATH

    Any executable named <bin>-<sub> on PATH is the command sub of bin: put hello-weather on PATH and hello weather runs it, with no change to the bin.

  2. 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>.

  3. 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 in commands --json.

  4. 04 / 06

    Merged command groups

    An inline group and an external <bin>-NAME on PATH are one group: their subcommands resolve together, each listed with its source.

  5. 05 / 06

    Handlers and input

    Cmd registers a handler with arguments, context and streams. Input, Text and Lines read files and stdin in order, with - for stdin.

  6. 06 / 06

    Standard library only

    No dependencies, injectable PATH and file system, builtins for help, commands, which and did-you-mean suggestions.

a shellconsole
$ 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