feat(plugin): add flags shorthand like kubectl
This commit is contained in:
parent
8114084b48
commit
a3e3eafe05
4 changed files with 13 additions and 16 deletions
|
@ -29,21 +29,16 @@ import (
|
||||||
|
|
||||||
// CreateCommand creates and returns this cobra subcommand
|
// CreateCommand creates and returns this cobra subcommand
|
||||||
func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
||||||
|
var service *string
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "info",
|
Use: "info",
|
||||||
Short: "Show information about the ingress-nginx service",
|
Short: "Show information about the ingress-nginx service",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
service, err := cmd.Flags().GetString("service")
|
util.PrintError(info(flags, *service))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
util.PrintError(info(flags, service))
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
service = util.AddServiceFlag(cmd)
|
||||||
cmd.Flags().String("service", util.DefaultIngressServiceName, "The name of the ingress-nginx service")
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import (
|
||||||
|
|
||||||
// CreateCommand creates and returns this cobra subcommand
|
// CreateCommand creates and returns this cobra subcommand
|
||||||
func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
||||||
|
var allNamespaces bool
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "ingresses",
|
Use: "ingresses",
|
||||||
Aliases: []string{"ingress", "ing"},
|
Aliases: []string{"ingress", "ing"},
|
||||||
|
@ -42,18 +43,12 @@ func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
allNamespaces, err := cmd.Flags().GetBool("all-namespaces")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
util.PrintError(ingresses(flags, host, allNamespaces))
|
util.PrintError(ingresses(flags, host, allNamespaces))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().String("host", "", "Show just the ingress definitions for this hostname")
|
cmd.Flags().String("host", "", "Show just the ingress definitions for this hostname")
|
||||||
cmd.Flags().Bool("all-namespaces", false, "Find ingress definitions from all namespaces")
|
cmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "Find ingress definitions from all namespaces")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ func addCommonOptions(flags *genericclioptions.ConfigFlags, cmd *cobra.Command)
|
||||||
out := lintOptions{
|
out := lintOptions{
|
||||||
flags: flags,
|
flags: flags,
|
||||||
}
|
}
|
||||||
cmd.Flags().BoolVar(&out.allNamespaces, "all-namespaces", false, "Check resources in all namespaces")
|
cmd.Flags().BoolVarP(&out.allNamespaces, "all-namespaces", "A", false, "Check resources in all namespaces")
|
||||||
cmd.Flags().BoolVar(&out.showAll, "show-all", false, "Show all resources, not just the ones with problems")
|
cmd.Flags().BoolVar(&out.showAll, "show-all", false, "Show all resources, not just the ones with problems")
|
||||||
cmd.Flags().BoolVarP(&out.verbose, "verbose", "v", false, "Show extra information about the lints")
|
cmd.Flags().BoolVarP(&out.verbose, "verbose", "v", false, "Show extra information about the lints")
|
||||||
cmd.Flags().StringVarP(&out.versionFrom, "from-version", "f", "0.0.0", "Use lints added for versions starting with this one")
|
cmd.Flags().StringVarP(&out.versionFrom, "from-version", "f", "0.0.0", "Use lints added for versions starting with this one")
|
||||||
|
|
|
@ -135,6 +135,13 @@ func AddContainerFlag(cmd *cobra.Command) *string {
|
||||||
return &v
|
return &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddServiceFlag adds a --service flag to a cobra command
|
||||||
|
func AddServiceFlag(cmd *cobra.Command) *string {
|
||||||
|
v := ""
|
||||||
|
cmd.Flags().StringVar(&v, "service", DefaultIngressServiceName, "The name of the ingress-nginx service")
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
// GetNamespace takes a set of kubectl flag values and returns the namespace we should be operating in
|
// GetNamespace takes a set of kubectl flag values and returns the namespace we should be operating in
|
||||||
func GetNamespace(flags *genericclioptions.ConfigFlags) string {
|
func GetNamespace(flags *genericclioptions.ConfigFlags) string {
|
||||||
namespace, _, err := flags.ToRawKubeConfigLoader().Namespace()
|
namespace, _, err := flags.ToRawKubeConfigLoader().Namespace()
|
||||||
|
|
Loading…
Reference in a new issue