larksuite/cli · error

required input cannot declare a default

Error message

required input cannot declare a default

What it means

mergeInputSupplement rejects an InputField.Default on a field whose schema tag marks it required (schema:"required"). A required input must always be explicitly provided, so a default is contradictory.

Source

Thrown at shortcuts/common/typed_compile_args.go:232

		shape, err := lowerAuthoringShape(supplement.Shape)
		if err != nil {
			return err
		}
		if err := validateShape(shape, "InputField.Shape"); err != nil {
			return err
		}
		if !shapeCompatibleWithType(shape, field.valueType) {
			return fmt.Errorf("InputField.Shape %T is incompatible with Go type %s", supplement.Shape, field.valueType)
		}
		field.shape = shape
		field.shapeExplicit = true
	}
	if supplement.Default.Set {
		if field.defaultValue.Set {
			return fmt.Errorf("default is declared by both schema and InputField.Default")
		}
		if field.required {
			return fmt.Errorf("required input cannot declare a default")
		}
		field.defaultValue = supplement.Default
	}
	if len(supplement.CLI.Aliases) > 0 {
		if len(field.cli.Aliases) > 0 {
			return fmt.Errorf("CLI.Aliases is declared by both cli tag and InputField.CLI")
		}
		field.cli.Aliases = append([]typedFlagAlias(nil), supplement.CLI.Aliases...)
	}
	if len(supplement.CLI.ValueSources) > 0 {
		if len(field.cli.ValueSources) > 0 {
			return fmt.Errorf("CLI.ValueSources is declared by both cli tag and InputField.CLI")
		}
		field.cli.ValueSources = append([]typedValueSource(nil), supplement.CLI.ValueSources...)
	}
	if supplement.CLI.Encoding != "" {
		if field.cli.Encoding != "" {
			return fmt.Errorf("CLI.Encoding is declared by both cli tag and InputField.CLI")

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Drop the InputField.Default if the input truly must be provided.
  2. Remove required from the schema tag if a default fallback is the desired behavior.

Example fix

// before
ID string `flag:"id" schema:"required"` + InputField{Name: "id", Default: ...}
// after
ID string `flag:"id" schema:"required"` (no InputField.Default)
Defensive patterns

Strategy: validation

Validate before calling

for _, f := range fields {
    if f.Required && f.InputDefault.Set {
        return fmt.Errorf("flag %s: required input cannot have default", f.Name)
    }
}

Prevention

When it happens

Trigger: compileInput -> mergeInputSupplement when supplement.Default.Set is true and field.required (from schema tag) is true.

Common situations: Marking a flag required in the schema tag while adding a fallback default via InputField.Default to 'be safe'.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/3d7057f2a4db92fa. Report an issue: GitHub.