forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
58 lines (51 loc) · 1.53 KB
/
root.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
package virtctl
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"flag"
"kubevirt.io/kubevirt/pkg/kubecli"
"kubevirt.io/kubevirt/pkg/virtctl/console"
"kubevirt.io/kubevirt/pkg/virtctl/offlinevm"
"kubevirt.io/kubevirt/pkg/virtctl/templates"
"kubevirt.io/kubevirt/pkg/virtctl/vnc"
)
func NewVirtctlCommand() *cobra.Command {
rootCmd := &cobra.Command{
Use: "virtctl",
Short: "virtctl controls virtual machine related operations on your kubernetes cluster.",
SilenceUsage: true,
SilenceErrors: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprint(cmd.OutOrStderr(), cmd.UsageString())
},
}
optionsCmd := &cobra.Command{
Use: "options",
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprint(cmd.OutOrStderr(), cmd.UsageString())
},
}
optionsCmd.SetUsageTemplate(templates.OptionsUsageTemplate())
//TODO: Add a ClientConfigFactory which allows substituting the KubeVirt client with a mock for unit testing
clientConfig := kubecli.DefaultClientConfig(rootCmd.PersistentFlags())
flag.CommandLine.Set("logtostderr", "true")
AddGlogFlags(rootCmd.PersistentFlags())
rootCmd.SetUsageTemplate(templates.MainUsageTemplate())
rootCmd.AddCommand(
console.NewCommand(clientConfig),
vnc.NewCommand(clientConfig),
offlinevm.NewStartCommand(clientConfig),
offlinevm.NewStopCommand(clientConfig),
optionsCmd,
)
return rootCmd
}
func Execute() {
if err := NewVirtctlCommand().Execute(); err != nil {
fmt.Println(strings.TrimSpace(err.Error()))
os.Exit(1)
}
}