-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a9d8fc
commit 60b8801
Showing
20 changed files
with
604 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## kn trigger list | ||
|
||
List available triggers. | ||
|
||
### Synopsis | ||
|
||
List available triggers. | ||
|
||
``` | ||
kn trigger list [name] [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# List all triggers | ||
kn trigger list | ||
# List all triggers in JSON output format | ||
kn trigger list -o json | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-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) | ||
-h, --help help for list | ||
-n, --namespace string Specify the namespace to operate in. | ||
--no-headers When using the default output format, don't print headers (default: print headers). | ||
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file. | ||
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string kn config file (default is $HOME/.kn/config.yaml) | ||
--kubeconfig string kubectl config file (default is $HOME/.kube/config) | ||
--log-http log http traffic | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kn trigger](kn_trigger.md) - Trigger command group | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright © 2019 The Knative Authors | ||
// | ||
// 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 flags | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"knative.dev/client/pkg/kn/commands" | ||
hprinters "knative.dev/client/pkg/printers" | ||
) | ||
|
||
// ListFlags composes common printer flag structs | ||
// used in the list command. | ||
type ListFlags struct { | ||
GenericPrintFlags *genericclioptions.PrintFlags | ||
HumanReadableFlags *commands.HumanPrintFlags | ||
PrinterHandler func(h hprinters.PrintHandler) | ||
} | ||
|
||
// AllowedFormats is the list of formats in which data can be displayed | ||
func (f *ListFlags) AllowedFormats() []string { | ||
formats := f.GenericPrintFlags.AllowedFormats() | ||
formats = append(formats, f.HumanReadableFlags.AllowedFormats()...) | ||
return formats | ||
} | ||
|
||
// ToPrinter attempts to find a composed set of ListTypesFlags suitable for | ||
// returning a printer based on current flag values. | ||
func (f *ListFlags) ToPrinter() (hprinters.ResourcePrinter, error) { | ||
// if there are flags specified for generic printing | ||
if f.GenericPrintFlags.OutputFlagSpecified() { | ||
p, err := f.GenericPrintFlags.ToPrinter() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return p, nil | ||
} | ||
|
||
p, err := f.HumanReadableFlags.ToPrinter(f.PrinterHandler) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return p, nil | ||
} | ||
|
||
// AddFlags receives a *cobra.Command reference and binds | ||
// flags related to humanreadable and template printing. | ||
func (f *ListFlags) AddFlags(cmd *cobra.Command) { | ||
f.GenericPrintFlags.AddFlags(cmd) | ||
f.HumanReadableFlags.AddFlags(cmd) | ||
} | ||
|
||
// NewListFlags returns flags associated with humanreadable, | ||
// template, and "name" printing, with default values set. | ||
func NewListFlags(printer func(h hprinters.PrintHandler)) *ListFlags { | ||
return &ListFlags{ | ||
GenericPrintFlags: genericclioptions.NewPrintFlags(""), | ||
HumanReadableFlags: commands.NewHumanPrintFlags(), | ||
PrinterHandler: printer, | ||
} | ||
} | ||
|
||
// EnsureWithNamespace ensures that humanreadable flags return | ||
// a printer capable of printing with a "namespace" column. | ||
func (f *ListFlags) EnsureWithNamespace() { | ||
f.HumanReadableFlags.EnsureWithNamespace() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright © 2019 The Knative Authors | ||
// | ||
// 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 flags | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"gotest.tools/assert" | ||
hprinters "knative.dev/client/pkg/printers" | ||
) | ||
|
||
func TestListFlagsFormats(t *testing.T) { | ||
flags := NewListFlags(nil) | ||
formats := flags.AllowedFormats() | ||
expected := []string{"json", "yaml", "name", "go-template", "go-template-file", "template", "templatefile", "jsonpath", "jsonpath-file", "no-headers"} | ||
assert.DeepEqual(t, formats, expected) | ||
} | ||
|
||
func TestListFlags(t *testing.T) { | ||
var cmd *cobra.Command | ||
flags := NewListFlags(func(h hprinters.PrintHandler) {}) | ||
|
||
cmd = &cobra.Command{} | ||
flags.AddFlags(cmd) | ||
|
||
assert.Assert(t, flags != nil) | ||
assert.Assert(t, cmd.Flags() != nil) | ||
|
||
allowMissingTemplateKeys, err := cmd.Flags().GetBool("allow-missing-template-keys") | ||
assert.NilError(t, err) | ||
assert.Assert(t, allowMissingTemplateKeys == true) | ||
|
||
p, err := flags.ToPrinter() | ||
assert.NilError(t, err) | ||
_, ok := p.(hprinters.ResourcePrinter) | ||
assert.Check(t, ok == true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.