Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export kubectl/cmd methods #2682

Merged
merged 1 commit into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/kubectl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ func runHelp(cmd *cobra.Command, args []string) {
cmd.Help()
}

func getKubeNamespace(cmd *cobra.Command) string {
// GetKubeNamespace returns the value of the namespace a
// user provided on the command line or use the default
// namespace.
func GetKubeNamespace(cmd *cobra.Command) string {
result := api.NamespaceDefault
if ns := GetFlagString(cmd, "namespace"); len(ns) > 0 {
result = ns
Expand All @@ -140,10 +143,10 @@ func getKubeNamespace(cmd *cobra.Command) string {
return result
}

// getExplicitKubeNamespace returns the value of the namespace a
// GetExplicitKubeNamespace returns the value of the namespace a
// user explicitly provided on the command line, or false if no
// such namespace was specified.
func getExplicitKubeNamespace(cmd *cobra.Command) (string, bool) {
func GetExplicitKubeNamespace(cmd *cobra.Command) (string, bool) {
if ns := GetFlagString(cmd, "namespace"); len(ns) > 0 {
return ns, true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Examples:

// use the default namespace if not specified, or check for conflict with the file's namespace
if len(namespace) == 0 {
namespace = getKubeNamespace(cmd)
namespace = GetKubeNamespace(cmd)
} else {
err = CompareNamespaceFromFile(cmd, namespace)
checkErr(err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubectl/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package cmd

import (
"github.com/spf13/cobra"
"io"

"github.com/spf13/cobra"
)

func (f *Factory) NewCmdLog(out io.Writer) *cobra.Command {
Expand All @@ -30,7 +31,7 @@ func (f *Factory) NewCmdLog(out io.Writer) *cobra.Command {
usageError(cmd, "<pod> and <container> are required for log")
}

namespace := getKubeNamespace(cmd)
namespace := GetKubeNamespace(cmd)

client, err := f.ClientBuilder.Client()
checkErr(err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubectl/cmd/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ResourceFromArgsOrFile(cmd *cobra.Command, args []string, filename string,

if len(args) == 2 {
resource := kubectl.ExpandResourceShortcut(args[0])
namespace = getKubeNamespace(cmd)
namespace = GetKubeNamespace(cmd)
name = args[1]
if len(name) == 0 || len(resource) == 0 {
usageError(cmd, "Must specify filename or command line params")
Expand Down Expand Up @@ -75,7 +75,7 @@ func ResourceFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTMapper)
}

resource := kubectl.ExpandResourceShortcut(args[0])
namespace = getKubeNamespace(cmd)
namespace = GetKubeNamespace(cmd)
name = args[1]
if len(name) == 0 || len(resource) == 0 {
usageError(cmd, "Must provide resource and name command line params")
Expand All @@ -102,7 +102,7 @@ func ResourceOrTypeFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTM
usageError(cmd, "Must provide resource or a resource and name as command line params")
}

namespace = getKubeNamespace(cmd)
namespace = GetKubeNamespace(cmd)
if len(args) == 2 {
name = args[1]
if len(name) == 0 {
Expand Down Expand Up @@ -154,7 +154,7 @@ func ResourceFromFile(filename string, typer runtime.ObjectTyper, mapper meta.RE
// or via the default namespace file does not match the namespace of an input file. This
// prevents a user from unintentionally updating the wrong namespace.
func CompareNamespaceFromFile(cmd *cobra.Command, namespace string) error {
defaultNamespace := getKubeNamespace(cmd)
defaultNamespace := GetKubeNamespace(cmd)
if len(namespace) > 0 {
if defaultNamespace != namespace {
return fmt.Errorf("the namespace from the provided file %q does not match the namespace %q. You must pass '--namespace=%s' to perform this operation.", namespace, defaultNamespace, namespace)
Expand Down