Honor help-only input checks before starting features

This commit is contained in:
2026-11-22 22:21:32 +00:00
parent 362afc79b6
commit 98e3958dfb
8 changed files with 121 additions and 15 deletions

View File

@@ -30,6 +30,7 @@ type InvocationFeatureSpec[I any] struct {
type invocationFeaturePayload interface {
bridgeFlags() []commandmeta.Flag
requiredError([][]string) error
prepare([][]string, [][]string, []commandmeta.FlagOccurrence, bool) (func(Invocation) (context.Context, func() Report), error)
}
@@ -39,6 +40,15 @@ func (f typedInvocationFeature[I]) bridgeFlags() []commandmeta.Flag {
return (typedCommand[I]{spec: CommandSpec[I]{Flags: f.spec.Flags}}).bridgeFlags()
}
func (f typedInvocationFeature[I]) requiredError(values [][]string) error {
for i, flag := range f.spec.Flags {
if flag.binding.meta.Required && !flag.binding.deferredRequired && len(values[i]) == 0 {
return fmt.Errorf("required flag --%s was not supplied", flag.binding.meta.Name)
}
}
return nil
}
func (f typedInvocationFeature[I]) prepare(values, spellings [][]string, occurrences []commandmeta.FlagOccurrence, required bool) (func(Invocation) (context.Context, func() Report), error) {
input, err := prepareInputWithOccurrences(CommandSpec[I]{NewInput: f.spec.NewInput, Flags: f.spec.Flags}, values, spellings, occurrences, nil, required)
if err != nil {