{"record":{"id":"3d7057f2a4db92fa","repo":"larksuite/cli","slug":"required-input-cannot-declare-a-default","errorCode":null,"errorMessage":"required input cannot declare a default","messagePattern":"required input cannot declare a default","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":232,"sourceCode":"\t\tshape, err := lowerAuthoringShape(supplement.Shape)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := validateShape(shape, \"InputField.Shape\"); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif !shapeCompatibleWithType(shape, field.valueType) {\n\t\t\treturn fmt.Errorf(\"InputField.Shape %T is incompatible with Go type %s\", supplement.Shape, field.valueType)\n\t\t}\n\t\tfield.shape = shape\n\t\tfield.shapeExplicit = true\n\t}\n\tif supplement.Default.Set {\n\t\tif field.defaultValue.Set {\n\t\t\treturn fmt.Errorf(\"default is declared by both schema and InputField.Default\")\n\t\t}\n\t\tif field.required {\n\t\t\treturn fmt.Errorf(\"required input cannot declare a default\")\n\t\t}\n\t\tfield.defaultValue = supplement.Default\n\t}\n\tif len(supplement.CLI.Aliases) > 0 {\n\t\tif len(field.cli.Aliases) > 0 {\n\t\t\treturn fmt.Errorf(\"CLI.Aliases is declared by both cli tag and InputField.CLI\")\n\t\t}\n\t\tfield.cli.Aliases = append([]typedFlagAlias(nil), supplement.CLI.Aliases...)\n\t}\n\tif len(supplement.CLI.ValueSources) > 0 {\n\t\tif len(field.cli.ValueSources) > 0 {\n\t\t\treturn fmt.Errorf(\"CLI.ValueSources is declared by both cli tag and InputField.CLI\")\n\t\t}\n\t\tfield.cli.ValueSources = append([]typedValueSource(nil), supplement.CLI.ValueSources...)\n\t}\n\tif supplement.CLI.Encoding != \"\" {\n\t\tif field.cli.Encoding != \"\" {\n\t\t\treturn fmt.Errorf(\"CLI.Encoding is declared by both cli tag and InputField.CLI\")","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L214-L250","documentation":"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.","triggerScenarios":"compileInput -> mergeInputSupplement when supplement.Default.Set is true and field.required (from schema tag) is true.","commonSituations":"Marking a flag required in the schema tag while adding a fallback default via InputField.Default to 'be safe'.","solutions":["Drop the InputField.Default if the input truly must be provided.","Remove required from the schema tag if a default fallback is the desired behavior."],"exampleFix":"// before\nID string `flag:\"id\" schema:\"required\"` + InputField{Name: \"id\", Default: ...}\n// after\nID string `flag:\"id\" schema:\"required\"` (no InputField.Default)","handlingStrategy":"validation","validationCode":"for _, f := range fields {\n    if f.Required && f.InputDefault.Set {\n        return fmt.Errorf(\"flag %s: required input cannot have default\", f.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat required and default as mutually exclusive when designing flag schemas.","Use Provided[T] fields instead of defaults for values callers must always supply.","Document the intent (mandatory vs optional-with-fallback) next to each flag."],"tags":["cli","typed-input","required","default-value"],"backgroundTag":"required-with-default","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}