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
f5ab3560
Unverified
Commit
f5ab3560
authored
Nov 17, 2017
by
juanvallejo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass printOpts by pointer
parent
d3773b4b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
28 deletions
+29
-28
view.go
pkg/kubectl/cmd/config/view.go
+1
-1
convert.go
pkg/kubectl/cmd/convert.go
+1
-1
get.go
pkg/kubectl/cmd/resource/get.go
+6
-6
fake.go
pkg/kubectl/cmd/testing/fake.go
+9
-9
factory.go
pkg/kubectl/cmd/util/factory.go
+2
-2
factory_builder.go
pkg/kubectl/cmd/util/factory_builder.go
+6
-5
printing.go
pkg/kubectl/cmd/util/printing.go
+4
-4
No files found.
pkg/kubectl/cmd/config/view.go
View file @
f5ab3560
...
...
@@ -82,7 +82,7 @@ func NewCmdConfigView(out, errOut io.Writer, ConfigAccess clientcmd.ConfigAccess
}
printOpts
:=
cmdutil
.
ExtractCmdPrintOptions
(
cmd
,
false
)
printer
,
err
:=
cmdutil
.
PrinterForOptions
(
meta
.
NewDefaultRESTMapper
(
nil
,
nil
),
latest
.
Scheme
,
nil
,
[]
runtime
.
Decoder
{
latest
.
Codec
},
*
printOpts
)
printer
,
err
:=
cmdutil
.
PrinterForOptions
(
meta
.
NewDefaultRESTMapper
(
nil
,
nil
),
latest
.
Scheme
,
nil
,
[]
runtime
.
Decoder
{
latest
.
Codec
},
printOpts
)
cmdutil
.
CheckErr
(
err
)
printer
=
printers
.
NewVersionedPrinter
(
printer
,
latest
.
Scheme
,
latest
.
ExternalVersion
)
...
...
pkg/kubectl/cmd/convert.go
View file @
f5ab3560
...
...
@@ -162,7 +162,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, out io.Writer, cmd *cobra.C
cmd
.
Flags
()
.
Set
(
"output"
,
outputFormat
)
}
o
.
encoder
=
f
.
JSONEncoder
()
o
.
printer
,
err
=
f
.
PrinterForOptions
(
printers
.
PrintOptions
{}
)
o
.
printer
,
err
=
f
.
PrinterForOptions
(
cmdutil
.
ExtractCmdPrintOptions
(
cmd
,
false
)
)
return
err
}
...
...
pkg/kubectl/cmd/resource/get.go
View file @
f5ab3560
...
...
@@ -255,7 +255,7 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str
}
printOpts
:=
cmdutil
.
ExtractCmdPrintOptions
(
cmd
,
options
.
AllNamespaces
)
printer
,
err
:=
f
.
PrinterForOptions
(
*
printOpts
)
printer
,
err
:=
f
.
PrinterForOptions
(
printOpts
)
if
err
!=
nil
{
return
err
}
...
...
@@ -331,11 +331,11 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str
printWithNamespace
=
false
}
printOpts
:=
*
cmdutil
.
ExtractCmdPrintOptions
(
cmd
,
printWithNamespace
)
printOpts
:=
cmdutil
.
ExtractCmdPrintOptions
(
cmd
,
printWithNamespace
)
// if cmd does not specify output format and useOpenAPIPrintColumnFlagLabel flag is true,
// then get the default output options for this mapping from OpenAPI schema.
if
!
cmdSpecifiesOutputFmt
(
cmd
)
&&
useOpenAPIPrintColumns
{
outputOptsForMappingFromOpenAPI
(
f
,
mapping
,
&
printOpts
)
updatePrintOptionsForOpenAPI
(
f
,
mapping
,
printOpts
)
}
printer
,
err
=
f
.
PrinterForMapping
(
printOpts
,
mapping
)
...
...
@@ -480,7 +480,7 @@ func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []s
info
:=
infos
[
0
]
mapping
:=
info
.
ResourceMapping
()
printOpts
:=
cmdutil
.
ExtractCmdPrintOptions
(
cmd
,
options
.
AllNamespaces
)
printer
,
err
:=
f
.
PrinterForMapping
(
*
printOpts
,
mapping
)
printer
,
err
:=
f
.
PrinterForMapping
(
printOpts
,
mapping
)
if
err
!=
nil
{
return
err
}
...
...
@@ -663,8 +663,8 @@ func cmdSpecifiesOutputFmt(cmd *cobra.Command) bool {
}
// outputOptsForMappingFromOpenAPI looks for the output format metatadata in the
// openapi schema and
returns the outpu
t options for the mapping if found.
func
outputOptsForMappingFrom
OpenAPI
(
f
cmdutil
.
Factory
,
mapping
*
meta
.
RESTMapping
,
printOpts
*
printers
.
PrintOptions
)
bool
{
// openapi schema and
modifies the passed prin
t options for the mapping if found.
func
updatePrintOptionsFor
OpenAPI
(
f
cmdutil
.
Factory
,
mapping
*
meta
.
RESTMapping
,
printOpts
*
printers
.
PrintOptions
)
bool
{
// user has not specified any output format, check if OpenAPI has
// default specification to print this resource type
...
...
pkg/kubectl/cmd/testing/fake.go
View file @
f5ab3560
...
...
@@ -352,17 +352,17 @@ func (f *FakeFactory) Describer(*meta.RESTMapping) (printers.Describer, error) {
return
f
.
tf
.
Describer
,
f
.
tf
.
Err
}
func
(
f
*
FakeFactory
)
PrinterForOptions
(
options
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
func
(
f
*
FakeFactory
)
PrinterForOptions
(
options
*
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
return
f
.
tf
.
Printer
,
f
.
tf
.
Err
}
func
(
f
*
FakeFactory
)
PrintResourceInfoForCommand
(
cmd
*
cobra
.
Command
,
info
*
resource
.
Info
,
out
io
.
Writer
)
error
{
printer
,
err
:=
f
.
PrinterForOptions
(
printers
.
PrintOptions
{})
printer
,
err
:=
f
.
PrinterForOptions
(
&
printers
.
PrintOptions
{})
if
err
!=
nil
{
return
err
}
if
!
printer
.
IsGeneric
()
{
printer
,
err
=
f
.
PrinterForMapping
(
printers
.
PrintOptions
{},
nil
)
printer
,
err
=
f
.
PrinterForMapping
(
&
printers
.
PrintOptions
{},
nil
)
if
err
!=
nil
{
return
err
}
...
...
@@ -513,7 +513,7 @@ func (f *FakeFactory) PrintObject(cmd *cobra.Command, isLocal bool, mapper meta.
return
nil
}
func
(
f
*
FakeFactory
)
PrinterForMapping
(
printOpts
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
{
func
(
f
*
FakeFactory
)
PrinterForMapping
(
printOpts
*
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
{
return
f
.
tf
.
Printer
,
f
.
tf
.
Err
}
...
...
@@ -744,17 +744,17 @@ func (f *fakeAPIFactory) UnstructuredClientForMapping(m *meta.RESTMapping) (reso
return
f
.
tf
.
UnstructuredClient
,
f
.
tf
.
Err
}
func
(
f
*
fakeAPIFactory
)
PrinterForOptions
(
options
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
func
(
f
*
fakeAPIFactory
)
PrinterForOptions
(
options
*
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
return
f
.
tf
.
Printer
,
f
.
tf
.
Err
}
func
(
f
*
fakeAPIFactory
)
PrintResourceInfoForCommand
(
cmd
*
cobra
.
Command
,
info
*
resource
.
Info
,
out
io
.
Writer
)
error
{
printer
,
err
:=
f
.
PrinterForOptions
(
printers
.
PrintOptions
{})
printer
,
err
:=
f
.
PrinterForOptions
(
&
printers
.
PrintOptions
{})
if
err
!=
nil
{
return
err
}
if
!
printer
.
IsGeneric
()
{
printer
,
err
=
f
.
PrinterForMapping
(
printers
.
PrintOptions
{},
nil
)
printer
,
err
=
f
.
PrinterForMapping
(
&
printers
.
PrintOptions
{},
nil
)
if
err
!=
nil
{
return
err
}
...
...
@@ -851,14 +851,14 @@ func (f *fakeAPIFactory) PrintObject(cmd *cobra.Command, isLocal bool, mapper me
return
err
}
printer
,
err
:=
f
.
PrinterForMapping
(
printers
.
PrintOptions
{},
mapping
)
printer
,
err
:=
f
.
PrinterForMapping
(
&
printers
.
PrintOptions
{},
mapping
)
if
err
!=
nil
{
return
err
}
return
printer
.
PrintObj
(
obj
,
out
)
}
func
(
f
*
fakeAPIFactory
)
PrinterForMapping
(
outputOpts
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
{
func
(
f
*
fakeAPIFactory
)
PrinterForMapping
(
outputOpts
*
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
{
return
f
.
tf
.
Printer
,
f
.
tf
.
Err
}
...
...
pkg/kubectl/cmd/util/factory.go
View file @
f5ab3560
...
...
@@ -230,12 +230,12 @@ type BuilderFactory interface {
// PrinterForCommand returns the default printer for the command. It requires that certain options
// are declared on the command (see AddPrinterFlags). Returns a printer, or an error if a printer
// could not be found.
PrinterForOptions
(
options
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
PrinterForOptions
(
options
*
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
// PrinterForMapping returns a printer suitable for displaying the provided resource type.
// Requires that printer flags have been added to cmd (see AddPrinterFlags).
// Returns a printer, true if the printer is generic (is not internal), or
// an error if a printer could not be found.
PrinterForMapping
(
options
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
PrinterForMapping
(
options
*
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
// PrintObject prints an api object given command line flags to modify the output format
PrintObject
(
cmd
*
cobra
.
Command
,
isLocal
bool
,
mapper
meta
.
RESTMapper
,
obj
runtime
.
Object
,
out
io
.
Writer
)
error
// PrintResourceInfoForCommand receives a *cobra.Command and a *resource.Info and
...
...
pkg/kubectl/cmd/util/factory_builder.go
View file @
f5ab3560
...
...
@@ -47,7 +47,7 @@ func NewBuilderFactory(clientAccessFactory ClientAccessFactory, objectMappingFac
return
f
}
func
(
f
*
ring2Factory
)
PrinterForOptions
(
options
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
func
(
f
*
ring2Factory
)
PrinterForOptions
(
options
*
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
var
mapper
meta
.
RESTMapper
var
typer
runtime
.
ObjectTyper
...
...
@@ -59,7 +59,7 @@ func (f *ring2Factory) PrinterForOptions(options printers.PrintOptions) (printer
return
PrinterForOptions
(
mapper
,
typer
,
encoder
,
decoders
,
options
)
}
func
(
f
*
ring2Factory
)
PrinterForMapping
(
options
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
{
func
(
f
*
ring2Factory
)
PrinterForMapping
(
options
*
printers
.
PrintOptions
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
ResourcePrinter
,
error
)
{
printer
,
err
:=
f
.
PrinterForOptions
(
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -124,7 +124,7 @@ func (f *ring2Factory) PrintObject(cmd *cobra.Command, isLocal bool, mapper meta
return
err
}
printer
,
err
:=
f
.
PrinterForMapping
(
printers
.
PrintOptions
{}
,
mapping
)
printer
,
err
:=
f
.
PrinterForMapping
(
ExtractCmdPrintOptions
(
cmd
,
false
)
,
mapping
)
if
err
!=
nil
{
return
err
}
...
...
@@ -132,12 +132,13 @@ func (f *ring2Factory) PrintObject(cmd *cobra.Command, isLocal bool, mapper meta
}
func
(
f
*
ring2Factory
)
PrintResourceInfoForCommand
(
cmd
*
cobra
.
Command
,
info
*
resource
.
Info
,
out
io
.
Writer
)
error
{
printer
,
err
:=
f
.
PrinterForOptions
(
printers
.
PrintOptions
{})
printOpts
:=
ExtractCmdPrintOptions
(
cmd
,
false
)
printer
,
err
:=
f
.
PrinterForOptions
(
printOpts
)
if
err
!=
nil
{
return
err
}
if
!
printer
.
IsGeneric
()
{
printer
,
err
=
f
.
PrinterForMapping
(
print
ers
.
PrintOptions
{}
,
nil
)
printer
,
err
=
f
.
PrinterForMapping
(
print
Opts
,
nil
)
if
err
!=
nil
{
return
err
}
...
...
pkg/kubectl/cmd/util/printing.go
View file @
f5ab3560
...
...
@@ -81,11 +81,11 @@ func ValidateOutputArgs(cmd *cobra.Command) error {
return
nil
}
//
p
rinterForOptions returns the printer for the outputOptions (if given) or
//
P
rinterForOptions returns the printer for the outputOptions (if given) or
// returns the default printer for the command. Requires that printer flags have
// been added to cmd (see AddPrinterFlags).
func
PrinterForOptions
(
mapper
meta
.
RESTMapper
,
typer
runtime
.
ObjectTyper
,
encoder
runtime
.
Encoder
,
decoders
[]
runtime
.
Decoder
,
options
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
printer
,
err
:=
printers
.
GetStandardPrinter
(
mapper
,
typer
,
encoder
,
decoders
,
options
)
func
PrinterForOptions
(
mapper
meta
.
RESTMapper
,
typer
runtime
.
ObjectTyper
,
encoder
runtime
.
Encoder
,
decoders
[]
runtime
.
Decoder
,
options
*
printers
.
PrintOptions
)
(
printers
.
ResourcePrinter
,
error
)
{
printer
,
err
:=
printers
.
GetStandardPrinter
(
mapper
,
typer
,
encoder
,
decoders
,
*
options
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -97,7 +97,7 @@ func PrinterForOptions(mapper meta.RESTMapper, typer runtime.ObjectTyper, encode
printersinternal
.
AddHandlers
(
humanReadablePrinter
)
}
return
maybeWrapSortingPrinter
(
printer
,
options
),
nil
return
maybeWrapSortingPrinter
(
printer
,
*
options
),
nil
}
// ExtractCmdPrintOptions parses printer specific commandline args and
...
...
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