-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
52 lines (40 loc) · 950 Bytes
/
main_test.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
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"testing"
"github.com/tucats/gopackages/app-cli/app"
"github.com/tucats/gopackages/app-cli/cli"
"github.com/tucats/gopackages/app-cli/tables"
)
var grammar = []cli.Option{
{
LongName: "test",
OptionType: cli.StringType,
Action: setTest,
},
}
func setTest(c *cli.Context) error {
fmt.Println("--test activated")
return nil
}
func defaultAction(c *cli.Context) error {
fmt.Println("In default action")
if c.WasFound("test") {
fmt.Println(c.String("test"))
}
f, _ := tables.New([]string{"Name", "Age"})
_ = f.AddRowItems("Tom", 63)
_ = f.AddRowItems("Mary", 58)
_ = f.AddRowItems("David", 29)
_ = f.AddRowItems("Bonnie", 73)
f.SetWhere("age < 60")
return f.Print("text")
}
func TestMain(t *testing.T) {
app := app.New("test driver").SetDefaultAction(defaultAction)
args := []string{"driver", "--test"}
err := app.Run(grammar, args[1:])
if err != nil {
fmt.Println(err)
}
}