Skip to content

Foxcapades/Argonaut

Repository files navigation

Argonaut

Argonaut is a builder-style CLI creation kit packed with features.

GitHub GitHub tag (latest SemVer) Argonaut Static Badge Wiki

import (
    cli "github.com/Foxcapades/Argonaut"
)

Features

  • Builder-style API.

    cli.Flag().
        WithArgument(cli.Argument().
            WithName("file").
            Require())
  • Build singular command applications or command trees.

    cli.Command()
    // OR
    cli.Tree()
  • Overridable automatic help text generation.

    Usage:
      my-app [options] <command>
        This is a simple command tree example.
    
    Flags
      -h | --help
          Prints this help text.
    
    Commands
      fizz    Aliases: fi
          This is the description for the fizz branch.
      foo     Aliases: fo
          this is the description for the foo branch
  • Bind command line arguments to variables of arbitrary types.

    foo := uint8(0)
    
    cli.Argument().WithBinding(&foo)
  • Multi-use flags.

    $ foo --bar --bar --bar
    bar = 3
  • Stackable short flags.

    $ app -abc=4
    a = true
    b = true
    c = 4
  • Callback hooks.

    cli.Flag().WithCallback(func(Flag){})
    cli.Command().WithCallback(func(Command){})
    cli.Tree().WithCallback(func(Tree){})
    cli.Branch().WithCallback(func(Branch){})
    cli.Leaf().WithCallback(func(Leaf){})
  • Customizable or overridable unmarshalling of almost any type.

    var options argo.UnmarshalProps
    ...
    cli.Argument().WithUnmarshaler(argo.NewMagicUnmarshaler(options))
  • Default values for flags and arguments.

    var foo int32
    cli.Argument().WithBinding(&foo).WithDefault(int32(666))
  • Input validation hooks.

    var bind uint8
    cli.Argument().
        WithBinding(&bind)
        WithValidator(func(string) {}).
        WithValidator(func(string, int8) {})
  • Automatic capturing of "passthrough" flags and arguments.

    $ foo bar --fizz=buzz -- apple banana canteloupe
    Passthroughs: apple, banana, canteloupe
  • And more!