-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_command_test.go
More file actions
61 lines (45 loc) · 1.34 KB
/
example_command_test.go
File metadata and controls
61 lines (45 loc) · 1.34 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
package cmder_test
import (
"context"
"fmt"
"github.com/brandon1024/cmder"
)
func ExampleCommand() {
cmd := &HelloWorldCommand{}
args := []string{"from", "cmder"}
if err := cmder.Execute(context.Background(), cmd, cmder.WithArgs(args)); err != nil {
fmt.Printf("unexpected error occurred: %v", err)
}
// Output:
// hello-world: [from cmder]
}
const HelloWorldCommandUsageLine = `hello-world [<args>...]`
const HelloWorldCommandShortHelpText = `Simple demonstration of cmder`
const HelloWorldCommandHelpText = `
'hello-world' demonstrates the simplest usage of cmder. This example defines a single command 'hello-world' that
implements the Runnable and Documented interfaces.
`
const HelloWorldCommandExamples = `
# broadcast hello to the world
hello-world from cmder
`
type HelloWorldCommand struct{}
func (c *HelloWorldCommand) Name() string {
return "hello-world"
}
func (c *HelloWorldCommand) Run(ctx context.Context, args []string) error {
fmt.Printf("%s: %v\n", c.Name(), args)
return nil
}
func (c *HelloWorldCommand) UsageLine() string {
return HelloWorldCommandUsageLine
}
func (c *HelloWorldCommand) ShortHelpText() string {
return HelloWorldCommandShortHelpText
}
func (c *HelloWorldCommand) HelpText() string {
return HelloWorldCommandHelpText
}
func (c *HelloWorldCommand) ExampleText() string {
return HelloWorldCommandExamples
}