-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathurfave-flags.go
More file actions
46 lines (37 loc) · 756 Bytes
/
urfave-flags.go
File metadata and controls
46 lines (37 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//go run urfave-flags.go --language spanish message TechTalks
package main
import (
"os"
"fmt"
"github.com/urfave/cli"
)
var language string
func main() {
app := cli.NewApp()
app.Version = "1.1"
app.Name = "hello-cli"
app.Usage = "A CLI tool for Tech Talks"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "language",
Value: "english",
Usage: "Select a language",
Destination: &language,
},
}
app.Commands = []cli.Command{
{
Name: "message",
Usage: "write a message",
Action: func(c *cli.Context) error {
if language == "spanish" {
fmt.Println("hola", c.Args().First())
} else {
fmt.Println("hello", c.Args().First())
}
return nil
},
},
}
app.Run(os.Args)
}