From b79f884410d3bed89d0346dd393791f715e1acc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarc=C3=ADsio=20Gruppi?= Date: Tue, 28 Jul 2015 20:06:46 +0200 Subject: [PATCH] Updated README.md with exit code sample --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 85b9cda..7c161a6 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ export PATH=$PATH:$GOPATH/bin ``` ## Getting Started -One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`. +One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`. ``` go package main @@ -57,7 +57,7 @@ func main() { app.Action = func(c *cli.Context) { println("boom! I say!") } - + app.Run(os.Args) } ``` @@ -251,6 +251,28 @@ app.Commands = []cli.Command{ ... ``` +### Exit code + +It is your responsability to call `os.Exit` with the exit code returned by +`app.Run` + +```go +package main + +import ( + "os" + "github.com/codegangsta/cli" +) + +func main() { + exitCode, err := cli.NewApp().Run(os.Args) + if err != nil { + log.Println(err) + } + os.Exit(exitCode) +} +``` + ### Bash Completion You can enable completion commands by setting the `EnableBashCompletion`