forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.go
63 lines (52 loc) · 1.39 KB
/
example.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
package cmd
import (
"fmt"
"io"
"os"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
)
var (
internalTYPELong = templates.LongDesc(`
Single line title
Description body`)
internalTYPEExample = templates.Examples(`%s`)
)
type TYPEOptions struct {
In io.Reader
Out, ErrOut io.Writer
}
// NewCmdTYPE implements a TYPE command
// This is an example type for templating.
func NewCmdTYPE(fullName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
options := &TYPEOptions{
In: in,
Out: out,
ErrOut: errout,
}
cmd := &cobra.Command{
Use: "NAME [...]",
Short: "A short description",
Long: internalTYPELong,
Example: fmt.Sprintf(internalTYPEExample, fullName),
Run: func(cmd *cobra.Command, args []string) {
kcmdutil.CheckErr(options.Complete(f, cmd, args))
kcmdutil.CheckErr(options.Validate())
if err := options.Run(); err != nil {
// TODO: move me to kcmdutil
if err == kcmdutil.ErrExit {
os.Exit(1)
}
kcmdutil.CheckErr(err)
}
},
}
return cmd
}
func (o *TYPEOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args []string) error {
return nil
}
func (o *TYPEOptions) Validate() error { return nil }
func (o *TYPEOptions) Run() error { return nil }