Debian Codegraph @

docs/v2/examples/exit-codes.md

raw symbols SCIP
1 ---
2 tags:
3 - v2
4 search:
5 boost: 2
6 ---
7
8 Calling `App.Run` will not automatically call `os.Exit`, which means that by
9 default the exit code will "fall through" to being `0`. An explicit exit code
10 may be set by returning a non-nil error that fulfills `cli.ExitCoder`, *or* a
11 `cli.MultiError` that includes an error that fulfills `cli.ExitCoder`, e.g.:
12 <!-- {
13 "error": "Ginger croutons are not in the soup"
14 } -->
15 ```go
16 package main
17
18 import (
19 "log"
20 "os"
21
22 "github.com/urfave/cli/v2"
23 )
24
25 func main() {
26 app := &cli.App{
27 Flags: []cli.Flag{
28 &cli.BoolFlag{
29 Name: "ginger-crouton",
30 Usage: "is it in the soup?",
31 },
32 },
33 Action: func(ctx *cli.Context) error {
34 if !ctx.Bool("ginger-crouton") {
35 return cli.Exit("Ginger croutons are not in the soup", 86)
36 }
37 return nil
38 },
39 }
40
41 if err := app.Run(os.Args); err != nil {
42 log.Fatal(err)
43 }
44 }
45 ```