MCPcopy
hub / github.com/argoproj/argo-workflows / NewRootCommand

Function NewRootCommand

cmd/argoexec/commands/root.go:31–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29}
30
31func NewRootCommand() *cobra.Command {
32 command := cobra.Command{
33 Use: CLIName,
34 Short: "argoexec is the executor sidecar to workflow containers",
35 RunE: func(cmd *cobra.Command, args []string) error {
36 return cmd.Help()
37 },
38 PersistentPreRun: func(cmd *cobra.Command, args []string) {
39 initConfig()
40 ctx, logger, err := cmdutil.CmdContextWithLogger(cmd, logLevel, logFormat)
41 if err != nil {
42 logging.InitLogger().WithError(err).WithFatal().Error(cmd.Context(), "Failed to create argoexec pre-run logger")
43 os.Exit(1)
44 }
45
46 // Required: argo=true field for test filtering compatibility
47 ctx = logging.WithLogger(ctx, logger.WithField("argo", true))
48 cmd.SetContext(ctx)
49
50 // Disable printing of usage string on errors, except for argument validation errors
51 // (i.e. when the "Args" function returns an error).
52 //
53 // This is set here instead of directly in "command" because Cobra
54 // executes PersistentPreRun after performing argument validation:
55 // https://github.com/spf13/cobra/blob/3a5efaede9d389703a792e2f7bfe3a64bc82ced9/command.go#L939-L957
56 cmd.SilenceUsage = true
57 },
58 }
59 command.AddCommand(NewAgentCommand())
60 command.AddCommand(NewArtifactPluginInitCommand())
61 command.AddCommand(NewArtifactPluginSidecarCommand())
62 command.AddCommand(NewEmissaryCommand())
63 command.AddCommand(NewInitCommand())
64 command.AddCommand(NewKillCommand())
65 command.AddCommand(NewResourceCommand())
66 command.AddCommand(NewWaitCommand())
67 command.AddCommand(NewDataCommand())
68 command.AddCommand(cmdutil.NewVersionCmd(CLIName))
69 command.AddCommand(artifact.NewArtifactCommand())
70
71 clientConfig = kubecli.AddKubectlFlagsToCmd(&command)
72 command.PersistentFlags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
73 command.PersistentFlags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level")
74 command.PersistentFlags().StringVar(&logFormat, "log-format", "text", "The formatter to use for logs. One of: text|json")
75
76 ctx, logger, err := cmdutil.CmdContextWithLogger(&command, logLevel, logFormat)
77 if err != nil {
78 logging.InitLogger().WithError(err).WithFatal().Error(command.Context(), "Failed to create argoexec logger")
79 os.Exit(1)
80 }
81
82 // Required: argo=true field for test filtering compatibility
83 ctx = logging.WithLogger(ctx, logger.WithField("argo", true))
84 command.SetContext(ctx)
85
86 return &command
87}

Callers 1

mainFunction · 0.92

Calls 15

InitLoggerFunction · 0.92
WithLoggerFunction · 0.92
NewArtifactCommandFunction · 0.92
initConfigFunction · 0.85
NewAgentCommandFunction · 0.85
NewEmissaryCommandFunction · 0.85
NewInitCommandFunction · 0.85
NewKillCommandFunction · 0.85
NewResourceCommandFunction · 0.85
NewDataCommandFunction · 0.85

Tested by

no test coverage detected