{"record":{"id":"fd6d190d68a5c30d","repo":"larksuite/cli","slug":"cli-encoding-is-declared-by-both-cli-tag-and-input","errorCode":null,"errorMessage":"CLI.Encoding is declared by both cli tag and InputField.CLI","messagePattern":"CLI\\.Encoding is declared by both cli tag and InputField\\.CLI","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":250,"sourceCode":"\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\")\n\t\t}\n\t\tfield.cli.Encoding = supplement.CLI.Encoding\n\t}\n\tif supplement.CLI.Hidden {\n\t\tif field.cli.Hidden {\n\t\t\treturn fmt.Errorf(\"CLI.Hidden is declared twice\")\n\t\t}\n\t\tfield.cli.Hidden = true\n\t}\n\tif supplement.CLI.Deprecated != \"\" {\n\t\tif field.cli.Deprecated != \"\" {\n\t\t\treturn fmt.Errorf(\"CLI.Deprecated is declared twice\")\n\t\t}\n\t\tfield.cli.Deprecated = supplement.CLI.Deprecated\n\t}\n\treturn nil\n}\n","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L232-L268","documentation":"mergeInputSupplement: the field already declares a cli-tag encoding and the InputField.CLI supplement also supplies Encoding - the two authoring surfaces are mutually exclusive per attribute to avoid ambiguity.","triggerScenarios":"compileInput -> mergeInputSupplement when supplement.CLI.Encoding != \"\" and field.cli.Encoding != \"\" (parsed from the cli tag).","commonSituations":"Setting encoding=json programmatically on a field that already has cli:\"encoding=json\" in its tag after copying configuration between declaration styles.","solutions":["Remove encoding= from the cli tag and set InputField.CLI.Encoding only.","Or clear InputField.CLI.Encoding if the tag declaration is authoritative."],"exampleFix":"// before\nPayload string `flag:\"payload\" cli:\"encoding=json\"` + InputField{CLI: CLI{Encoding: \"json\"}}\n// after\nPayload string `flag:\"payload\"` + InputField{CLI: CLI{Encoding: \"json\"}}","handlingStrategy":"validation","validationCode":"for _, f := range fields {\n    if f.TagEncoding != \"\" && f.InputEncoding != \"\" {\n        return fmt.Errorf(\"flag %s: encoding declared twice\", f.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare encoding in exactly one channel per flag.","When a field needs encoding=json, prefer the InputField.CLI.Encoding route and drop tag encodings."],"tags":["cli","typed-input","duplicate-declaration","encoding"],"backgroundTag":"conflicting-declaration","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"}