{"record":{"id":"afbcc4e6e28a856f","repo":"larksuite/cli","slug":"valuesources-must-include-flag","errorCode":null,"errorMessage":"ValueSources must include flag","messagePattern":"ValueSources must include flag","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":293,"sourceCode":"\t}\n\tif field.defaultValue.Set {\n\t\tif err := valueAssignableTo(field.defaultValue.Value, field.valueType); err != nil {\n\t\t\treturn fmt.Errorf(\"default: %w\", err)\n\t\t}\n\t}\n\tseenSources := make(map[typedValueSource]struct{})\n\tfor _, source := range field.cli.ValueSources {\n\t\tif source != typedSourceFlag && source != typedSourceFile && source != typedSourceStdin {\n\t\t\treturn fmt.Errorf(\"unknown value source %q\", source)\n\t\t}\n\t\tif _, duplicate := seenSources[source]; duplicate {\n\t\t\treturn fmt.Errorf(\"duplicate value source %q\", source)\n\t\t}\n\t\tseenSources[source] = struct{}{}\n\t}\n\tif len(field.cli.ValueSources) > 0 {\n\t\tif _, ok := seenSources[typedSourceFlag]; !ok {\n\t\t\treturn fmt.Errorf(\"ValueSources must include flag\")\n\t\t}\n\t\tif (len(seenSources) > 1) && indirectKind(field.valueType) != reflect.String && field.cli.Encoding != typedEncodingJSON {\n\t\t\treturn fmt.Errorf(\"file/stdin sources require string input or encoding=json\")\n\t\t}\n\t}\n\tkind := indirectKind(field.valueType)\n\tif kind == reflect.Slice || kind == reflect.Array || kind == reflect.Struct || kind == reflect.Map || kind == reflect.Interface {\n\t\tif field.cli.Encoding == \"\" {\n\t\t\treturn fmt.Errorf(\"%s input must explicitly declare CLI encoding\", kind)\n\t\t}\n\t}\n\tswitch field.cli.Encoding {\n\tcase \"\":\n\t\tif kind == reflect.Slice || kind == reflect.Array || kind == reflect.Struct || kind == reflect.Map || kind == reflect.Interface {\n\t\t\treturn fmt.Errorf(\"complex input requires encoding\")\n\t\t}\n\tcase typedEncodingRepeated:\n\t\tif kind != reflect.Slice && kind != reflect.Array {","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L275-L311","documentation":"When ValueSources is non-empty, the flag source is mandatory: multi-source inputs are defined as 'flag first, optionally supplemented by file/stdin'. validateInputCLI rejects a list like [file] or [stdin] alone because a field whose value never comes from the command line flag breaks the CLI contract for primary inputs.","triggerScenarios":"Declaring ValueSources without \"flag\", e.g. ValueSources: []string{\"file\"} or []string{\"file\",\"stdin\"}, intending to read the value only from a file or stdin. Raised by compileInput during shortcut compilation.","commonSituations":"Assuming a field can be file-only or stdin-only; building a 'silent' input that is never shown as a flag; misunderstanding that ValueSources is additive to flag rather than a replacement.","solutions":["Add \"flag\" as the first entry of ValueSources","If the field must not be a CLI flag, do not use ValueSources - hide the flag (CLI.Hidden) instead","Remove ValueSources entirely to fall back to the default flag-only behavior"],"exampleFix":"// before\nValueSources: []string{\"file\", \"stdin\"}\n// after\nValueSources: []string{\"flag\", \"file\", \"stdin\"}","handlingStrategy":"validation","validationCode":"func hasFlagSource(srcs []string) bool {\n\tfor _, s := range srcs {\n\t\tif s == \"flag\" {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n// require len(srcs) == 0 || hasFlagSource(srcs)","typeGuard":null,"tryCatchPattern":"if err := compileInput(...); err != nil {\n\tif strings.Contains(err.Error(), \"must include flag\") {\n\t\t// prepend \"flag\" to ValueSources\n\t}\n\treturn err\n}","preventionTips":["Always list flag first when using ValueSources","Remember ValueSources supplements the flag; it never replaces it","Use CLI.Hidden for inputs that should not appear as flags"],"tags":["cli","shortcut-input","value-sources","flag-required"],"backgroundTag":"cli-invalid-value-source","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"}