{"record":{"id":"1fa2180306fbfcb9","repo":"larksuite/cli","slug":"input-fields-contains-duplicate-flag-q","errorCode":null,"errorMessage":"Input.Fields contains duplicate flag %q","messagePattern":"Input\\.Fields contains duplicate flag %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_compile_args.go","lineNumber":34,"sourceCode":"\nvar (\n\tflagNamePattern  = regexp.MustCompile(`^[a-z0-9]+(?:-[a-z0-9]+)*$`)\n\taliasNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]*$`)\n)\n\nconst extensionCommandPkgPath = \"github.com/larksuite/cli/extension/command\"\n\nfunc compileInput(argsType reflect.Type, definition typedInputDefinition) ([]compiledInputField, map[string]int, error) {\n\tif argsType.Kind() != reflect.Struct {\n\t\treturn nil, nil, fmt.Errorf(\"Args must be a non-pointer struct, got %s\", argsType)\n\t}\n\tsupplements := make(map[string]typedInputField, len(definition.Fields))\n\tfor i, supplement := range definition.Fields {\n\t\tif !flagNamePattern.MatchString(supplement.Name) {\n\t\t\treturn nil, nil, fmt.Errorf(\"Input.Fields[%d].Name %q is not a canonical flag name\", i, supplement.Name)\n\t\t}\n\t\tif _, exists := supplements[supplement.Name]; exists {\n\t\t\treturn nil, nil, fmt.Errorf(\"Input.Fields contains duplicate flag %q\", supplement.Name)\n\t\t}\n\t\tsupplements[supplement.Name] = supplement\n\t}\n\tvar fields []compiledInputField\n\tseenGo := make(map[string]struct{})\n\tif err := collectArgFields(argsType, nil, false, &fields, seenGo, supplements); err != nil {\n\t\treturn nil, nil, err\n\t}\n\tfieldByName := make(map[string]int, len(fields))\n\tallNames := make(map[string]string, len(fields))\n\tfor i := range fields {\n\t\tfield := &fields[i]\n\t\tif previous, exists := allNames[field.name]; exists {\n\t\t\treturn nil, nil, fmt.Errorf(\"Args field %s flag --%s duplicates %s\", field.goName, field.name, previous)\n\t\t}\n\t\tallNames[field.name] = \"--\" + field.name\n\t\tfieldByName[field.name] = i\n\t\tsupplement, hasSupplement := supplements[field.name]","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_compile_args.go#L16-L52","documentation":"compileInput builds a map of supplemental Input.Fields keyed by flag name and rejects definitions that declare the same flag name twice. Duplicate names would make the merge into compiled fields ambiguous, so the second occurrence triggers this error.","triggerScenarios":"Listing two typedInputField entries with identical Name values (e.g. two entries named \"user-id\") in the same typedInputDefinition.Fields and compiling the definition.","commonSituations":"Copy-pasting a supplement entry and forgetting to change its name; merging two definitions whose Fields slices overlap; generating Fields programmatically where a loop emits one name twice.","solutions":["Remove the duplicate Input.Fields entry.","Rename one of the duplicates to a distinct canonical flag name.","If both supplements target the same struct field, merge their metadata (Description/CLI) into a single entry."],"exampleFix":"// before\nFields: []typedInputField{\n  {Name: \"user-id\", Description: \"user id\"},\n  {Name: \"user-id\", Description: \"override\"},\n}\n// after\nFields: []typedInputField{\n  {Name: \"user-id\", Description: \"user id override\"},\n}","handlingStrategy":"validation","validationCode":"func noDuplicateSupplements(fields []typedInputField) error {\n  seen := map[string]bool{}\n  for _, f := range fields {\n    if seen[f.Name] { return fmt.Errorf(\"duplicate Input.Field %q\", f.Name) }\n    seen[f.Name] = true\n  }\n  return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate generated Fields slices before compiling.","Name supplements after the struct field's flag to keep mapping 1:1.","Add a compile-all-definitions test in CI."],"tags":["go","flags","duplicates","validation"],"backgroundTag":"duplicate-flag-definition","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"}