-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_example_test.go
More file actions
90 lines (79 loc) · 2.89 KB
/
command_example_test.go
File metadata and controls
90 lines (79 loc) · 2.89 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
package core_test
import (
. "dappco.re/go"
)
// ExampleCommand_I18nKey builds an i18n key through `Command.I18nKey` for managed CLI
// command dispatch. Command registration and lookup use managed metadata before execution.
func ExampleCommand_I18nKey() {
cmd := &Command{Path: "deploy/to/homelab"}
Println(cmd.I18nKey())
// Output: cmd.deploy.to.homelab.description
}
// ExampleCommand_Run runs `Command.Run` with representative caller inputs for managed CLI
// command dispatch. Command registration and lookup use managed metadata before execution.
func ExampleCommand_Run() {
cmd := &Command{
Action: func(opts Options) Result {
return Result{Value: opts.String("target"), OK: true}
},
}
r := cmd.Run(NewOptions(Option{Key: "target", Value: "homelab"}))
Println(r.Value)
// Output: homelab
}
// ExampleCommand_IsManaged checks managed command state through `Command.IsManaged` for
// managed CLI command dispatch. Command registration and lookup use managed metadata
// before execution.
func ExampleCommand_IsManaged() {
cmd := &Command{Managed: "process.daemon"}
Println(cmd.IsManaged())
// Output: true
}
// ExampleCore_Command_register registers a value through `Core.Command` for managed CLI
// command dispatch. Command registration and lookup use managed metadata before execution.
func ExampleCore_Command_register() {
c := New()
c.Command("deploy/to/homelab", Command{
Description: "Deploy to homelab",
Action: func(opts Options) Result {
return Result{Value: "deployed", OK: true}
},
})
Println(c.Command("deploy/to/homelab").OK)
// Output: true
}
// ExampleCore_Command_get retrieves a value through `Core.Command` for managed CLI command
// dispatch. Command registration and lookup use managed metadata before execution.
func ExampleCore_Command_get() {
c := New()
c.Command("deploy", Command{Action: func(_ Options) Result { return Result{OK: true} }})
r := c.Command("deploy")
cmd := r.Value.(*Command)
Println(cmd.Name)
Println(cmd.Path)
// Output:
// deploy
// deploy
}
// ExampleCore_Command_managed registers managed command metadata through `Core.Command`
// for managed CLI command dispatch. Command registration and lookup use managed metadata
// before execution.
func ExampleCore_Command_managed() {
c := New()
c.Command("serve", Command{
Action: func(_ Options) Result { return Result{OK: true} },
Managed: "process.daemon",
})
cmd := c.Command("serve").Value.(*Command)
Println(cmd.IsManaged())
// Output: true
}
// ExampleCore_Commands lists command names through `Core.Commands` for managed CLI command
// dispatch. Command registration and lookup use managed metadata before execution.
func ExampleCore_Commands() {
c := New()
c.Command("deploy", Command{Action: func(_ Options) Result { return Result{OK: true} }})
c.Command("test", Command{Action: func(_ Options) Result { return Result{OK: true} }})
Println(c.Commands())
// Output: [deploy test]
}