MCPcopy Index your code
hub / github.com/riverqueue/river / BaseCommandSet

Method BaseCommandSet

cmd/river/rivercli/river_cli.go:59–372  ·  view source on GitHub ↗

BaseCommandSet provides a base River CLI command set which may be further augmented with additional commands.

()

Source from the content-addressed store, hash-verified

57// BaseCommandSet provides a base River CLI command set which may be further
58// augmented with additional commands.
59func (c *CLI) BaseCommandSet() *cobra.Command {
60 ctx := context.Background()
61
62 var globalOpts struct {
63 Debug bool
64 StatementTimeout time.Duration
65 Verbose bool
66 }
67 var rootCmd *cobra.Command
68
69 makeLogger := func() *slog.Logger {
70 switch {
71 case globalOpts.Debug:
72 return slog.New(tint.NewHandler(os.Stdout, &tint.Options{Level: slog.LevelDebug}))
73 case globalOpts.Verbose:
74 return slog.New(tint.NewHandler(os.Stdout, nil))
75 default:
76 return slog.New(tint.NewHandler(os.Stdout, &tint.Options{Level: slog.LevelWarn}))
77 }
78 }
79
80 statementTimeoutFlagSet := func() bool {
81 return rootCmd.PersistentFlags().Changed("statement-timeout")
82 }
83
84 validateGlobalOpts := func() error {
85 if statementTimeoutFlagSet() && globalOpts.StatementTimeout <= time.Millisecond {
86 return errors.New("`--statement-timeout` must be greater than 1ms when set")
87 }
88
89 return nil
90 }
91
92 // Make a bundle for RunCommand. Takes a database URL pointer because not every command is required to take a database URL.
93 makeCommandBundle := func(databaseURL *string, schema string) *RunCommandBundle {
94 var statementTimeout *time.Duration
95 if statementTimeoutFlagSet() {
96 statementTimeout = &globalOpts.StatementTimeout
97 }
98
99 return &RunCommandBundle{
100 DatabaseURL: databaseURL,
101 DriverProcurer: c.driverProcurer,
102 Logger: makeLogger(),
103 OutStd: c.out,
104 Schema: schema,
105 StatementTimeout: statementTimeout,
106 }
107 }
108
109 {
110 var rootOpts struct {
111 Version bool
112 }
113
114 rootCmd = &cobra.Command{
115 Use: "river",
116 Short: "Provides command line facilities for the River job queue",

Calls 2

RunCommandFunction · 0.85
SetOutMethod · 0.80