Document shared debug input and reporting mode
This commit is contained in:
@@ -154,6 +154,35 @@ Deferred submissions are accepted until finalization begins; later submissions
|
||||
return `ErrReporterClosed`. The [CLI reference](../cli.md#reporting) owns flag
|
||||
grammar, visibility, prefixes, and status behavior.
|
||||
|
||||
An application can attach a boolean input to the shared `--debug` option and
|
||||
inspect the reporting selection separately. For example:
|
||||
|
||||
```go
|
||||
type input struct { debug commandkit.Supplied[bool] }
|
||||
|
||||
command := commandkit.NewCommand(commandkit.CommandSpec[input]{
|
||||
Name: "run",
|
||||
Flags: []commandkit.Flag[input]{
|
||||
commandkit.BoolFlag(commandkit.FlagMeta{Name: "debug", Short: "d"}, false,
|
||||
func(in *input, value commandkit.Supplied[bool]) { in.debug = value }),
|
||||
},
|
||||
Run: func(inv commandkit.Invocation, in input) commandkit.Outcome {
|
||||
captureArtifacts := in.debug.Value
|
||||
quiet := inv.ReportingMode() == commandkit.ReportingModeQuiet
|
||||
_, _ = captureArtifacts, quiet // Apply application policy here.
|
||||
return commandkit.Success()
|
||||
},
|
||||
})
|
||||
_ = command
|
||||
```
|
||||
|
||||
With `run --debug --quiet`, the input is true and explicitly supplied, while
|
||||
the selected reporting mode is quiet. Application defaults and requiredness
|
||||
affect input, not mode selection; explicit false counts as supplied. Captured
|
||||
bindings retain the usual selection and application behavior. Applications own
|
||||
any artifact creation and other effects. The mode reports selection rather than
|
||||
successful delivery; see [Invocation.ReportingMode](../../identity.go).
|
||||
|
||||
Reports use JSON serialization to establish the common value representation
|
||||
for YAML and JSON. A text template receives the original value; without one,
|
||||
text uses readable scalar or string-list output and YAML for structured values.
|
||||
|
||||
Reference in New Issue
Block a user