forked from openshift/origin
/
helpers.go
40 lines (35 loc) · 1023 Bytes
/
helpers.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
package cmd
import (
"os"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
kubecmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/golang/glog"
"github.com/spf13/cobra"
)
func usageError(cmd *cobra.Command, format string, args ...interface{}) {
glog.Errorf(format, args...)
glog.Errorf("See '%s -h' for help.", cmd.CommandPath())
os.Exit(1)
}
func checkErr(err error) {
if err != nil {
glog.FatalDepth(1, err)
}
}
func getOriginNamespace(cmd *cobra.Command) string {
result := kapi.NamespaceDefault
if ns := kubecmd.GetFlagString(cmd, "namespace"); len(ns) > 0 {
result = ns
glog.V(2).Infof("Using namespace from -ns flag")
} else {
nsPath := kubecmd.GetFlagString(cmd, "ns-path")
nsInfo, err := kubectl.LoadNamespaceInfo(nsPath)
if err != nil {
glog.Fatalf("Error loading current namespace: %v", err)
}
result = nsInfo.Namespace
}
glog.V(2).Infof("Using namespace %s", result)
return result
}