-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.go
82 lines (70 loc) · 1.53 KB
/
cmd.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
78
79
80
81
82
package firebasecli
import (
"fmt"
"io"
"os"
)
// Cmd executes command.
type Cmd struct {
// Sub holds sub commands.
Sub map[string]Runnable
// App holds App.
App *App
// Stdout holds standard output where a command outputs.
// Set nil to suppress output.
Stdout io.Writer
// Stderr holds standard error where a command outputs.
// Set nil to suppress output.
Stderr io.Writer
}
// NewCmd returns a new initialized Cmd.
func NewCmd() *Cmd {
return &Cmd{
make(map[string]Runnable),
&App{},
os.Stdout,
os.Stderr,
}
}
// Print prints to stdout.
func (c *Cmd) Print(a ...interface{}) (int, error) {
if c.Stdout == nil {
return 0, nil
}
return fmt.Fprint(c.Stdout, a...)
}
// Println prints to stdout.
func (c *Cmd) Println(a ...interface{}) (int, error) {
if c.Stdout == nil {
return 0, nil
}
return fmt.Fprintln(c.Stdout, a...)
}
// Printf prints to stdout.
func (c *Cmd) Printf(format string, a ...interface{}) (int, error) {
if c.Stdout == nil {
return 0, nil
}
return fmt.Fprintf(c.Stdout, format, a...)
}
// Eprint prints to stderr.
func (c *Cmd) Eprint(a ...interface{}) (int, error) {
if c.Stderr == nil {
return 0, nil
}
return fmt.Fprint(c.Stderr, a...)
}
// Eprintln prints to stderr.
func (c *Cmd) Eprintln(a ...interface{}) (int, error) {
if c.Stderr == nil {
return 0, nil
}
return fmt.Fprintln(c.Stderr, a...)
}
// Eprintf prints to stderr.
func (c *Cmd) Eprintf(format string, a ...interface{}) (int, error) {
if c.Stderr == nil {
return 0, nil
}
return fmt.Fprintf(c.Stderr, format, a...)
}