Releases: jwaldrip/odin
Version 1.8.0
Version 1.7.0
Features:
Outputs functionality is now part of odin.
Output Helpers
Output is possible directly on the CLI and is prefered over using fmt. Available commands map to their fmt counterparts.
method | description |
---|---|
ErrPrint(a ...interface{}) |
Prints to the err output. |
ErrPrintf(format string, a ...interface{}) |
Prints formatted to the err output. |
ErrPrintln(a ...interface{}) |
Prints a line to the err output. |
Print(a ...interface{}) |
Prints to the std output. |
Printf(format string, a ...interface{}) |
Prints formatted to the std output. |
Println(a ...interface{}) |
Prints a line to the std output. |
package main
import "github.com/jwaldrip/odin/cli"
app := cli.New("1.0.0", "my app", func(c cli.Command){
c.Println("hello world")
c.ErrPrintln("There was an error")
}
Custom Output
Any io.Writer
can be used as an output
outbuffer := bytes.NewBufferString("")
errbuffer := bytes.NewBufferString("")
app.SetStdOut(outbuffer)
app.SetStdErr(errbuffer)
Version 1.6.2
Version 1.6.1
Fixes
Help was updated to ensure all descriptions for flags and commands line up properly.
before:
$ go run -- examples/greet-with/main.go hello to -h
Usage:
main [options...] <greeting> to <greetee>
Say a greeting to a specific persion
Example:
$ greet-with hello to jerry
hello jerry
Options:
-h, --help # show help and exit
Options for `main`:
-c, --color="blue" # color the output (red, blue, green)
-h, --help # show help and exit
-l, --loudly # say loudly
-v, --version # show version and exit
after:
$ go run -- examples/greet-with/main.go hello to -h
Usage:
main [options...] <greeting> to <greetee>
Say a greeting to a specific persion
Example:
$ greet-with hello to jerry
hello jerry
Options:
-h, --help : show help and exit
Options for `main`:
-h, --help : show help and exit
-v, --version : show version and exit
-l, --loudly : say loudly
-c, --color=blue : color the output (red, blue, green)
Version 1.6.0
Features
- Supports for long descriptions using
SetLongDescription()
which will only show up on--help
invoked directly on a command.
Enhancements
-
Help is now slightly more verbose. Showing more information about the parent commands on sub commands.
_example:_
$ greet-with hello to -h Usage: greet-with [options...] <greeting> to <greetee> Say a greeting to a specific persion Example: $ greet-with hello to jerry hello jerry Options: -h, --help # show help and exit Options for `greet-with`: -c, --color="blue" # color the output (red, blue, green) -h, --help # show help and exit -l, --loudly # say loudly -v, --version # show version and exit
Version 1.5.1
Fixes:
- Flag not parsing when flags are placed after freeform arguments.
Version 1.5.0
Features
- Odin now supports flags before or after the parameters for the given command.
_example:_
$ go run main.go hello --loudly
HELLO
$ go run main.go --loudly hello
HELLO
_main.go:_
package main
import (
"fmt"
"strings"
"github.com/jwaldrip/odin/cli"
)
var app = cli.New("0.0.1", "say a word", func(c cli.Command) {
str := c.Param("word").String()
if c.Flag("loudly").Get() == true {
str = strings.ToUpper(str)
}
fmt.Println(str)
})
func init() {
app.DefineParams("word")
app.DefineBoolFlag("loudly", false, "say it loudly")
}
func main() {
app.Start()
}
View the PR: #13
Special thanks to @dcarley for this request!!
Version 1.4.3
Several Fixes Related to Sub Commands and Flag inheritance.
Version 1.4.2
_kudos to @dcarley:_
The default for ErrorHandling
was changed from ContinueOnError
to
PanicOnError
8c20e9b. However this didn't apply to sub-commands, which
continued to use ContinueOnError
and would execute the sub-command
function (in addition to printing the usage message) when not passed
mandatory arguments.
Fix this by copying ErrorHandling
from the parent when adding a new
sub-command. The additional test asserts that the sub-command raises a panic
and doesn't execute it's contents when it doesn't receive the correct number
of arguments. Mute is required to prevent the help message being printed
during the tests.
Version 1.4.1
Fixes:
- #7 - When
ErrorHandling
is set toContinueOnError
... an error is raised.