MCPcopy Create free account
hub / github.com/cogentcore/core / Run

Function Run

cli/cli.go:33–64  ·  view source on GitHub ↗

Run runs an app with the given options, configuration struct, and commands. It does not run the GUI; see [cogentcore.org/core/cli/clicore.Run] for that. The configuration struct should be passed as a pointer, and configuration options should be defined as fields on the configuration struct. The comm

(opts *Options, cfg T, cmds ...C)

Source from the content-addressed store, hash-verified

31// true, the error result of Run does not need to be handled. Run uses
32// [os.Args] for its arguments.
33func Run[T any, C CmdOrFunc[T]](opts *Options, cfg T, cmds ...C) error {
34 cs, err := CmdsFromCmdOrFuncs[T, C](cmds)
35 if err != nil {
36 err := fmt.Errorf("internal/programmer error: error getting commands from given commands: %w", err)
37 if opts.Fatal {
38 logx.PrintError(err)
39 os.Exit(1)
40 }
41 return err
42 }
43 cmd, err := config(opts, cfg, cs...)
44 if err != nil {
45 if opts.Fatal {
46 logx.PrintlnError("error: ", err)
47 os.Exit(1)
48 }
49 return err
50 }
51 err = runCmd(opts, cfg, cmd, cs...)
52 if err != nil {
53 if opts.Fatal {
54 fmt.Println(logx.CmdColor(cmdString(cmd)) + logx.ErrorColor(" failed: "+err.Error()))
55 os.Exit(1)
56 }
57 return fmt.Errorf("%s failed: %w", cmdName()+" "+cmd, err)
58 }
59 // if the user sets level to error (via -q), we don't show the success message
60 if opts.PrintSuccess && logx.UserLevel <= slog.LevelWarn {
61 fmt.Println(logx.CmdColor(cmdString(cmd)) + logx.SuccessColor(" succeeded"))
62 }
63 return nil
64}
65
66// runCmd runs the command with the given name using the given options,
67// configuration information, and available commands. If the given

Callers 9

mainFunction · 0.92
mainFunction · 0.92
RunFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
TestRunFunction · 0.70

Calls 13

PrintErrorFunction · 0.92
PrintlnErrorFunction · 0.92
CmdColorFunction · 0.92
ErrorColorFunction · 0.92
SuccessColorFunction · 0.92
configFunction · 0.85
runCmdFunction · 0.85
cmdStringFunction · 0.85
cmdNameFunction · 0.85
ExitMethod · 0.80
PrintlnMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestRunFunction · 0.56