mirror of https://github.com/knative/client.git
Add support for -A variant of --all-namespaces (#356)
* Add support for -A variant of --all-namespaces -A is my newest favorite kubectl flag, it's so much easier/faster to type than --all-namespaces. kn users should benefit from it too! Signed-off-by: Doug Davis <dug@us.ibm.com> * tweak tests Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
parent
8c362f0363
commit
74b3e10f76
|
|
@ -30,7 +30,7 @@ kn revision list [name] [flags]
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
|
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
|
||||||
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
|
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
|
||||||
-h, --help help for list
|
-h, --help help for list
|
||||||
-n, --namespace string List the requested object(s) in given namespace.
|
-n, --namespace string List the requested object(s) in given namespace.
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ kn route list NAME [flags]
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
|
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
|
||||||
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
|
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
|
||||||
-h, --help help for list
|
-h, --help help for list
|
||||||
-n, --namespace string List the requested object(s) in given namespace.
|
-n, --namespace string List the requested object(s) in given namespace.
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ kn service list [name] [flags]
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
|
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
|
||||||
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
|
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
|
||||||
-h, --help help for list
|
-h, --help help for list
|
||||||
-n, --namespace string List the requested object(s) in given namespace.
|
-n, --namespace string List the requested object(s) in given namespace.
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,9 @@ func AddNamespaceFlags(flags *pflag.FlagSet, allowAll bool) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if allowAll {
|
if allowAll {
|
||||||
flags.Bool(
|
flags.BoolP(
|
||||||
"all-namespaces",
|
"all-namespaces",
|
||||||
|
"A",
|
||||||
false,
|
false,
|
||||||
"If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.",
|
"If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.",
|
||||||
)
|
)
|
||||||
|
|
@ -43,7 +44,7 @@ func AddNamespaceFlags(flags *pflag.FlagSet, allowAll bool) {
|
||||||
// GetNamespace returns namespace from command specified by flag
|
// GetNamespace returns namespace from command specified by flag
|
||||||
func (params *KnParams) GetNamespace(cmd *cobra.Command) (string, error) {
|
func (params *KnParams) GetNamespace(cmd *cobra.Command) (string, error) {
|
||||||
namespace := cmd.Flag("namespace").Value.String()
|
namespace := cmd.Flag("namespace").Value.String()
|
||||||
// check value of all-namepace only if its defined
|
// check value of all-namepaces only if its defined
|
||||||
if cmd.Flags().Lookup("all-namespaces") != nil {
|
if cmd.Flags().Lookup("all-namespaces") != nil {
|
||||||
all, err := cmd.Flags().GetBool("all-namespaces")
|
all, err := cmd.Flags().GetBool("all-namespaces")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,10 @@ func TestGetNamespaceAllNamespacesSet(t *testing.T) {
|
||||||
testCmd := testCommandGenerator(true)
|
testCmd := testCommandGenerator(true)
|
||||||
expectedNamespace := ""
|
expectedNamespace := ""
|
||||||
sampleNamespace := "test1"
|
sampleNamespace := "test1"
|
||||||
testCmd.SetArgs([]string{"--namespace", sampleNamespace, "--all-namespaces"})
|
|
||||||
|
// Test both variants of the "all namespaces" flag
|
||||||
|
for _, arg := range []string{"--all-namespaces", "-A"} {
|
||||||
|
testCmd.SetArgs([]string{"--namespace", sampleNamespace, arg})
|
||||||
testCmd.Execute()
|
testCmd.Execute()
|
||||||
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
|
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
|
||||||
actualNamespace, err := kp.GetNamespace(testCmd)
|
actualNamespace, err := kp.GetNamespace(testCmd)
|
||||||
|
|
@ -78,6 +81,8 @@ func TestGetNamespaceAllNamespacesSet(t *testing.T) {
|
||||||
if actualNamespace != expectedNamespace {
|
if actualNamespace != expectedNamespace {
|
||||||
t.Fatalf("Incorrect namespace retrieved: %v, expected: %v", actualNamespace, expectedNamespace)
|
t.Fatalf("Incorrect namespace retrieved: %v, expected: %v", actualNamespace, expectedNamespace)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test with all-namespace flag set without any namespace flag set
|
// test with all-namespace flag set without any namespace flag set
|
||||||
|
|
@ -85,7 +90,10 @@ func TestGetNamespaceAllNamespacesSet(t *testing.T) {
|
||||||
func TestGetNamespaceDefaultAllNamespacesUnset(t *testing.T) {
|
func TestGetNamespaceDefaultAllNamespacesUnset(t *testing.T) {
|
||||||
testCmd := testCommandGenerator(true)
|
testCmd := testCommandGenerator(true)
|
||||||
expectedNamespace := ""
|
expectedNamespace := ""
|
||||||
testCmd.SetArgs([]string{"--all-namespaces"})
|
|
||||||
|
// Test both variants of the "all namespaces" flag
|
||||||
|
for _, arg := range []string{"--all-namespaces", "-A"} {
|
||||||
|
testCmd.SetArgs([]string{arg})
|
||||||
testCmd.Execute()
|
testCmd.Execute()
|
||||||
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
|
kp := &KnParams{fixedCurrentNamespace: FakeNamespace}
|
||||||
actualNamespace, err := kp.GetNamespace(testCmd)
|
actualNamespace, err := kp.GetNamespace(testCmd)
|
||||||
|
|
@ -95,6 +103,8 @@ func TestGetNamespaceDefaultAllNamespacesUnset(t *testing.T) {
|
||||||
if actualNamespace != expectedNamespace {
|
if actualNamespace != expectedNamespace {
|
||||||
t.Fatalf("Incorrect namespace retrieved: %v, expected: %v", actualNamespace, expectedNamespace)
|
t.Fatalf("Incorrect namespace retrieved: %v, expected: %v", actualNamespace, expectedNamespace)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test with all-namespaces flag not defined for command
|
// test with all-namespaces flag not defined for command
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue