Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
314eb1ae
Commit
314eb1ae
authored
Jul 14, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #454 from brendandburns/template
Add a template printer to kubecfg.
parents
540be9de
b2ef24fb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
3 deletions
+44
-3
kubecfg.go
cmd/kubecfg/kubecfg.go
+27
-3
resource_printer.go
pkg/kubecfg/resource_printer.go
+17
-0
No files found.
cmd/kubecfg/kubecfg.go
View file @
314eb1ae
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"os"
"os"
"strconv"
"strconv"
"strings"
"strings"
"text/template"
"time"
"time"
kube_client
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
kube_client
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
...
@@ -50,6 +51,8 @@ var (
...
@@ -50,6 +51,8 @@ var (
verbose
=
flag
.
Bool
(
"verbose"
,
false
,
"If true, print extra information"
)
verbose
=
flag
.
Bool
(
"verbose"
,
false
,
"If true, print extra information"
)
proxy
=
flag
.
Bool
(
"proxy"
,
false
,
"If true, run a proxy to the api server"
)
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"
)
www
=
flag
.
String
(
"www"
,
""
,
"If -proxy is true, use this directory to serve static files"
)
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
()
{
func
usage
()
{
...
@@ -184,11 +187,32 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
...
@@ -184,11 +187,32 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
}
}
var
printer
kubecfg
.
ResourcePrinter
var
printer
kubecfg
.
ResourcePrinter
if
*
json
{
switch
{
case
*
json
:
printer
=
&
kubecfg
.
IdentityPrinter
{}
printer
=
&
kubecfg
.
IdentityPrinter
{}
}
else
if
*
yaml
{
case
*
yaml
:
printer
=
&
kubecfg
.
YAMLPrinter
{}
printer
=
&
kubecfg
.
YAMLPrinter
{}
}
else
{
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
{
glog
.
Fatalf
(
"Error parsing template %s, %v
\n
"
,
string
(
data
),
err
)
return
false
}
printer
=
&
kubecfg
.
TemplatePrinter
{
Template
:
tmpl
,
}
default
:
printer
=
&
kubecfg
.
HumanReadablePrinter
{}
printer
=
&
kubecfg
.
HumanReadablePrinter
{}
}
}
...
...
pkg/kubecfg/resource_printer.go
View file @
314eb1ae
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"io"
"io"
"strings"
"strings"
"text/tabwriter"
"text/tabwriter"
"text/template"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
...
@@ -235,3 +236,19 @@ func (h *HumanReadablePrinter) PrintObj(obj interface{}, output io.Writer) error
...
@@ -235,3 +236,19 @@ func (h *HumanReadablePrinter) PrintObj(obj interface{}, output io.Writer) error
return
err
return
err
}
}
}
}
type
TemplatePrinter
struct
{
Template
*
template
.
Template
}
func
(
t
*
TemplatePrinter
)
Print
(
data
[]
byte
,
w
io
.
Writer
)
error
{
obj
,
err
:=
api
.
Decode
(
data
)
if
err
!=
nil
{
return
err
}
return
t
.
PrintObj
(
obj
,
w
)
}
func
(
t
*
TemplatePrinter
)
PrintObj
(
obj
interface
{},
w
io
.
Writer
)
error
{
return
t
.
Template
.
Execute
(
w
,
obj
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment