-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.go
77 lines (64 loc) · 1.83 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
. "github.com/saschagrunert/demo" //nolint:stylecheck // dot imports are intended here
"github.com/urfave/cli/v2"
)
func main() {
// Create a new demo CLI application
demo := New()
// A demo is an usual urfave/cli application, which means
// that we can set its properties as expected:
demo.Name = "A demo of something"
demo.Usage = "Learn how this framework is being used"
demo.HideVersion = true
// Be able to run a Setup/Cleanup function before/after each run
demo.Setup(setup)
demo.Cleanup(cleanup)
// Register the demo run
demo.Add(example(), "demo-0", "just an example demo run")
// Run the application, which registers all signal handlers and waits for
// the app to exit
demo.Run()
}
// setup will run before every demo.
func setup(*cli.Context) error {
// Ensure can be used for easy sequential command execution
return Ensure(
"echo 'Doing first setup…'",
"echo 'Doing second setup…'",
"echo 'Doing third setup…'",
)
}
// setup will run after every demo.
func cleanup(*cli.Context) error {
return Ensure("echo 'Doing cleanup…'")
}
// example is the single demo run for this application.
func example() *Run {
// A new run contains a title and an optional description
r := NewRun(
"Demo Title",
"Some additional",
"multi-line description",
"is possible as well!",
)
// A single step can consist of a description and a command to be executed
r.Step(S(
"This is a possible",
"description of the following command",
"to be executed",
), S(
"echo hello world",
))
// Commands do not need to have a description, so we could set it to `nil`
r.Step(nil, S(
"echo without description",
"but this can be executed in",
"multiple lines as well",
))
// It is also not needed at all to provide a command
r.Step(S(
"Just a description without a command",
), nil)
return r
}