package sink import ( "io" "github.com/go-logr/logr" "edge-infra.dev/pkg/lib/cli/clog" "edge-infra.dev/pkg/lib/fog" ) // Run contains the execution-scoped CLI machinery and state for a single // [Command] invocation, e.g., output writers, logging, the parsed and computed // [Command], etc. Extensions can manipulate the [Run] state by implementing // [BeforeRunner] or [AfterRunner], allowing middleware-style state passing and // CLI logic reuse. type Run struct { Log logr.Logger // Read only execution state. cmd *Command args []string out io.Writer err io.Writer } // Cmd returns the parsed and computed [Command] associated with this run func (r Run) Cmd() *Command { return r.cmd } // Out returns the standard output stream for the command invocation func (r Run) Out() io.Writer { return r.out } // Err returns the error output stream for the command invocation func (r Run) Err() io.Writer { return r.err } // Args returns the non-flag arguments remaining after parsing command line input. func (r Run) Args() []string { return r.args } func newRun(c *Command) Run { r := Run{ cmd: c, out: c.getOut(), err: c.getErr(), args: c.args, } // TODO(aw185176): Decouple log construction so that Command isnt tightly // coupled to specific logr impls switch { case c.logJSON: r.Log = fog.New( fog.WithLevel(c.logLvl), fog.To(r.Err()), ) default: r.Log = clog.New( clog.To(r.Err()), clog.WithLevel(c.logLvl), clog.WithCaller(clog.Error), ) } return r }