-
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
Daisy Guo
committed
Dec 17, 2019
1 parent
6ac25cd
commit 85cbea1
Showing
11 changed files
with
413 additions
and
3 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 trigger. | ||
|
||
### Synopsis | ||
|
||
List available trigger. | ||
|
||
``` | ||
kn trigger list [name] [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# List all trigger | ||
kn trigger list | ||
# List all trigger 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,84 @@ | ||
// 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" | ||
) | ||
|
||
// ListFlagsPrinterHandler is the printer handler for HumanReadableFlags | ||
type ListFlagsPrinterHandler interface { | ||
ListPrinter(h hprinters.PrintHandler) | ||
} | ||
|
||
// 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,77 @@ | ||
// 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 trigger | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"knative.dev/client/pkg/kn/commands" | ||
"knative.dev/client/pkg/kn/commands/flags" | ||
) | ||
|
||
// NewTriggerListCommand represents 'kn trigger list' command | ||
func NewTriggerListCommand(p *commands.KnParams) *cobra.Command { | ||
triggerListFlags := flags.NewListFlags(TriggerListHandlers) | ||
|
||
triggerListCommand := &cobra.Command{ | ||
Use: "list [name]", | ||
Short: "List available trigger.", | ||
Example: ` | ||
# List all trigger | ||
kn trigger list | ||
# List all trigger in JSON output format | ||
kn trigger list -o json`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
namespace, err := p.GetNamespace(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
client, err := p.NewEventingClient(namespace) | ||
if err != nil { | ||
return err | ||
} | ||
triggerList, err := client.ListTriggers() | ||
if err != nil { | ||
return err | ||
} | ||
if len(triggerList.Items) == 0 { | ||
fmt.Fprintf(cmd.OutOrStdout(), "No trigger found.\n") | ||
return nil | ||
} | ||
|
||
// empty namespace indicates all-namespaces flag is specified | ||
if namespace == "" { | ||
triggerListFlags.EnsureWithNamespace() | ||
} | ||
|
||
printer, err := triggerListFlags.ToPrinter() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = printer.PrintObj(triggerList, cmd.OutOrStdout()) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
commands.AddNamespaceFlags(triggerListCommand.Flags(), true) | ||
triggerListFlags.AddFlags(triggerListCommand) | ||
return triggerListCommand | ||
} |
Oops, something went wrong.