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
500bb3a7
Commit
500bb3a7
authored
Jan 20, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make kubectl factory flag binding optional
parent
6ff26d92
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
4 deletions
+52
-4
gen_kubectl_docs.go
cmd/gendocs/gen_kubectl_docs.go
+1
-1
kubectl.go
cmd/kubectl/kubectl.go
+1
-1
cmd.go
pkg/kubectl/cmd/cmd.go
+9
-2
factory_test.go
pkg/kubectl/cmd/factory_test.go
+41
-0
No files found.
cmd/gendocs/gen_kubectl_docs.go
View file @
500bb3a7
...
@@ -30,7 +30,7 @@ func main() {
...
@@ -30,7 +30,7 @@ func main() {
// Set environment variables used by kubectl so the output is consistent,
// Set environment variables used by kubectl so the output is consistent,
// regardless of where we run.
// regardless of where we run.
os
.
Setenv
(
"HOME"
,
"/home/username"
)
os
.
Setenv
(
"HOME"
,
"/home/username"
)
kubectl
:=
cmd
.
NewFactory
()
.
NewKubectlCommand
(
out
)
kubectl
:=
cmd
.
NewFactory
(
nil
)
.
NewKubectlCommand
(
out
)
fmt
.
Fprintf
(
out
,
"## %s
\n\n
"
,
kubectl
.
Name
())
fmt
.
Fprintf
(
out
,
"## %s
\n\n
"
,
kubectl
.
Name
())
fmt
.
Fprintf
(
out
,
"%s
\n\n
"
,
kubectl
.
Short
)
fmt
.
Fprintf
(
out
,
"%s
\n\n
"
,
kubectl
.
Short
)
fmt
.
Fprintln
(
out
,
"### Commands
\n
"
)
fmt
.
Fprintln
(
out
,
"### Commands
\n
"
)
...
...
cmd/kubectl/kubectl.go
View file @
500bb3a7
...
@@ -23,7 +23,7 @@ import (
...
@@ -23,7 +23,7 @@ import (
)
)
func
main
()
{
func
main
()
{
cmd
:=
cmd
.
NewFactory
()
.
NewKubectlCommand
(
os
.
Stdout
)
cmd
:=
cmd
.
NewFactory
(
nil
)
.
NewKubectlCommand
(
os
.
Stdout
)
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
if
err
:=
cmd
.
Execute
();
err
!=
nil
{
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
...
pkg/kubectl/cmd/cmd.go
View file @
500bb3a7
...
@@ -69,11 +69,18 @@ type Factory struct {
...
@@ -69,11 +69,18 @@ type Factory struct {
}
}
// NewFactory creates a factory with the default Kubernetes resources defined
// NewFactory creates a factory with the default Kubernetes resources defined
func
NewFactory
()
*
Factory
{
// if optionalClientConfig is nil, then flags will be bound to a new clientcmd.ClientConfig.
// if optionalClientConfig is not nil, then this factory will make use of it.
func
NewFactory
(
optionalClientConfig
clientcmd
.
ClientConfig
)
*
Factory
{
mapper
:=
kubectl
.
ShortcutExpander
{
latest
.
RESTMapper
}
mapper
:=
kubectl
.
ShortcutExpander
{
latest
.
RESTMapper
}
flags
:=
pflag
.
NewFlagSet
(
""
,
pflag
.
ContinueOnError
)
flags
:=
pflag
.
NewFlagSet
(
""
,
pflag
.
ContinueOnError
)
clientConfig
:=
DefaultClientConfig
(
flags
)
clientConfig
:=
optionalClientConfig
if
optionalClientConfig
==
nil
{
clientConfig
=
DefaultClientConfig
(
flags
)
}
clients
:=
&
clientCache
{
clients
:=
&
clientCache
{
clients
:
make
(
map
[
string
]
*
client
.
Client
),
clients
:
make
(
map
[
string
]
*
client
.
Client
),
loader
:
clientConfig
,
loader
:
clientConfig
,
...
...
pkg/kubectl/cmd/factory_test.go
0 → 100644
View file @
500bb3a7
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
cmd
import
(
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
clientcmdapi
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
)
func
TestNewFactoryDefaultFlagBindings
(
t
*
testing
.
T
)
{
factory
:=
NewFactory
(
nil
)
if
!
factory
.
flags
.
HasFlags
()
{
t
.
Errorf
(
"Expected flags, but didn't get any"
)
}
}
func
TestNewFactoryNoFlagBindings
(
t
*
testing
.
T
)
{
clientConfig
:=
clientcmd
.
NewDefaultClientConfig
(
*
clientcmdapi
.
NewConfig
(),
&
clientcmd
.
ConfigOverrides
{})
factory
:=
NewFactory
(
clientConfig
)
if
factory
.
flags
.
HasFlags
()
{
t
.
Errorf
(
"Expected zero flags, but got %v"
,
factory
.
flags
)
}
}
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