test(08-07): add failing repeatable-flag RED anchor for bonfire
- TestPhase8RedBonfireFlags asserts Input.Flags preserves ordered repeated --redirect-uri/--scope values while existing scalar --mode flags via Input.Flag stay unaffected - Adds the compiling seam (Flag.Repeatable, Input.Flags, cobraInput.Flags) without wiring Cobra StringSlice registration yet, so the test fails with PHASE8_RED:bonfire-flags (D-19)
This commit is contained in:
@@ -28,6 +28,13 @@ type Flag struct {
|
||||
Default string
|
||||
// Bare allows --flag without a value; cobra stores "true".
|
||||
Bare bool
|
||||
// Repeatable registers this flag as an ordered, multi-occurrence
|
||||
// string flag (Cobra StringSlice) instead of a scalar string flag
|
||||
// (08-CONTEXT.md D-19; 08-PATTERNS.md "bonfire repeatable-flag gap").
|
||||
// Repeated `--name=a --name=b` preserves insertion order and is read
|
||||
// back through Input.Flags, never Input.Flag. Existing scalar/bare
|
||||
// flags are unaffected: Repeatable defaults to false.
|
||||
Repeatable bool
|
||||
}
|
||||
|
||||
// Arg describes a positional argument.
|
||||
@@ -42,6 +49,10 @@ type Input interface {
|
||||
Args() []string
|
||||
Argument(name string) (string, bool)
|
||||
Flag(name string) (string, bool)
|
||||
// Flags returns the ordered, repeated values of a Repeatable flag
|
||||
// (D-19). It returns nil for a scalar/bare flag or an unset repeatable
|
||||
// flag; callers must use Flag for scalar flags.
|
||||
Flags(name string) []string
|
||||
}
|
||||
|
||||
type cobraInput struct {
|
||||
@@ -64,6 +75,20 @@ func (in cobraInput) Argument(name string) (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Flags returns the ordered values of a Repeatable (Cobra StringSlice)
|
||||
// flag. It returns nil if the flag was never registered as repeatable
|
||||
// (wrong pflag type) or the command has no flag set (08-CONTEXT.md D-19).
|
||||
func (in cobraInput) Flags(name string) []string {
|
||||
if in.cmd == nil || in.cmd.Flags() == nil {
|
||||
return nil
|
||||
}
|
||||
vals, err := in.cmd.Flags().GetStringSlice(name)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (in cobraInput) Flag(name string) (string, bool) {
|
||||
if in.cmd == nil || in.cmd.Flags() == nil {
|
||||
return "", false
|
||||
|
||||
Reference in New Issue
Block a user