Files
David XiaandGitHub 56812bec02 kubectl-plugin: set global flags at the root cmd (#3203)
instead of setting them each time on every leaf command.
This has several benefits

* global flags are available for every command (root, intermediate, and leaves)
* help messages are as expected for every command. No more misleading ones for
  invalid commands.
* simplifies the code and prevents the chance of forgetting to add the global
  flags for future commands
* makes the plugin behave more like `kubectl` in that the K8s context is
  optional for all commands

Signed-off-by: David Xia <[email protected]>
2025-03-26 13:53:56 -07:00

29 lines
773 B
Go

package create
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)
func NewCreateCommand(cmdFactory cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Create Ray resources",
Long: `Allow users to create Ray resources. And based on input, will generate the necessary files`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
fmt.Println(fmt.Errorf("unknown command(s) %q", strings.Join(args, " ")))
}
cmd.HelpFunc()(cmd, args)
},
}
cmd.AddCommand(NewCreateClusterCommand(cmdFactory, streams))
cmd.AddCommand(NewCreateWorkerGroupCommand(cmdFactory, streams))
return cmd
}