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)
| 31 | // true, the error result of Run does not need to be handled. Run uses |
| 32 | // [os.Args] for its arguments. |
| 33 | func 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 |