Address comments.

pull/6/head
Brendan Burns 2014-07-14 21:29:31 -07:00
parent f7bd5a6f0f
commit b2ef24fb48
1 changed files with 17 additions and 9 deletions

View File

@ -51,7 +51,8 @@ var (
verbose = flag.Bool("verbose", false, "If true, print extra information")
proxy = flag.Bool("proxy", false, "If true, run a proxy to the api server")
www = flag.String("www", "", "If -proxy is true, use this directory to serve static files")
templateFile = flag.String("template", "", "If present load this file as a golang template and us it for output printing")
templateFile = flag.String("template_file", "", "If present load this file as a golang template and us it for output printing")
templateStr = flag.String("template", "", "If present parse this string as a golang template and us it for output printing")
)
func usage() {
@ -186,15 +187,22 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
}
var printer kubecfg.ResourcePrinter
if *json {
switch {
case *json:
printer = &kubecfg.IdentityPrinter{}
} else if *yaml {
case *yaml:
printer = &kubecfg.YAMLPrinter{}
} else if len(*templateFile) > 0 {
data, err := ioutil.ReadFile(*templateFile)
if err != nil {
glog.Fatalf("Error reading template %s, %v\n", *templateFile, err)
return false
case len(*templateFile) > 0 || len(*templateStr) > 0:
var data []byte
if len(*templateFile) > 0 {
var err error
data, err = ioutil.ReadFile(*templateFile)
if err != nil {
glog.Fatalf("Error reading template %s, %v\n", *templateFile, err)
return false
}
} else {
data = []byte(*templateStr)
}
tmpl, err := template.New("output").Parse(string(data))
if err != nil {
@ -204,7 +212,7 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
printer = &kubecfg.TemplatePrinter{
Template: tmpl,
}
} else {
default:
printer = &kubecfg.HumanReadablePrinter{}
}