Honor help-only input checks before starting features
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user