-
Notifications
You must be signed in to change notification settings - Fork 0
/
sayhello_parse.go
40 lines (34 loc) · 1.26 KB
/
sayhello_parse.go
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
package main
import (
"fmt"
"github.com/ariary/quicli/pkg/quicli"
)
func main() {
cli := quicli.Cli{
Usage: "SayToTheWorld [flags]",
Description: "Say Hello... or not. If you want to make the world aware of it you also could",
Flags: quicli.Flags{
{Name: "count", Default: 1, Description: "how many times I want to say it. Sometimes repetition is the key"},
{Name: "say", Default: "hello", Description: "say something. If you are polite start with a greeting"},
{Name: "world", Description: "announce it to the world"},
},
}
cfg := cli.Parse()
for i := 0; i < cfg.GetIntFlag("count"); i++ {
if cfg.GetBoolFlag("world") {
fmt.Print("Message for the world: ")
}
fmt.Println(cfg.GetStringFlag("say"))
}
}
// ALTERNATIVE
// cfg := quicli.Parse(quicli.Cli{
// Usage: "SayToTheWorld [flags]",
// Description: "Say Hello... or not. If you want to make the world aware of it you also could",
// Flags: quicli.Flags{
// {Name: "count", Default: 1, Description: "how many times I want to say it. Sometimes repetition is the key"},
// {Name: "say", Default: "hello", Description: "say something. If you are polite start with a greeting"},
// {Name: "world", Description: "announce it to the world"},
// },
// Function: SayHello,
// })