larksuite/cli · error
Input.Fields contains duplicate flag %q
Error message
Input.Fields contains duplicate flag %q
What it means
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.
Source
Thrown at shortcuts/common/typed_compile_args.go:34
var (
flagNamePattern = regexp.MustCompile(`^[a-z0-9]+(?:-[a-z0-9]+)*$`)
aliasNamePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]*$`)
)
const extensionCommandPkgPath = "github.com/larksuite/cli/extension/command"
func compileInput(argsType reflect.Type, definition typedInputDefinition) ([]compiledInputField, map[string]int, error) {
if argsType.Kind() != reflect.Struct {
return nil, nil, fmt.Errorf("Args must be a non-pointer struct, got %s", argsType)
}
supplements := make(map[string]typedInputField, len(definition.Fields))
for i, supplement := range definition.Fields {
if !flagNamePattern.MatchString(supplement.Name) {
return nil, nil, fmt.Errorf("Input.Fields[%d].Name %q is not a canonical flag name", i, supplement.Name)
}
if _, exists := supplements[supplement.Name]; exists {
return nil, nil, fmt.Errorf("Input.Fields contains duplicate flag %q", supplement.Name)
}
supplements[supplement.Name] = supplement
}
var fields []compiledInputField
seenGo := make(map[string]struct{})
if err := collectArgFields(argsType, nil, false, &fields, seenGo, supplements); err != nil {
return nil, nil, err
}
fieldByName := make(map[string]int, len(fields))
allNames := make(map[string]string, len(fields))
for i := range fields {
field := &fields[i]
if previous, exists := allNames[field.name]; exists {
return nil, nil, fmt.Errorf("Args field %s flag --%s duplicates %s", field.goName, field.name, previous)
}
allNames[field.name] = "--" + field.name
fieldByName[field.name] = i
supplement, hasSupplement := supplements[field.name]View on GitHub (pinned to 7fd6ef3c07)
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.
Example fix
// before
Fields: []typedInputField{
{Name: "user-id", Description: "user id"},
{Name: "user-id", Description: "override"},
}
// after
Fields: []typedInputField{
{Name: "user-id", Description: "user id override"},
} Defensive patterns
Strategy: validation
Validate before calling
func noDuplicateSupplements(fields []typedInputField) error {
seen := map[string]bool{}
for _, f := range fields {
if seen[f.Name] { return fmt.Errorf("duplicate Input.Field %q", f.Name) }
seen[f.Name] = true
}
return nil
} Prevention
- 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.
When it happens
Trigger: Listing two typedInputField entries with identical Name values (e.g. two entries named "user-id") in the same typedInputDefinition.Fields and compiling the definition.
Common situations: 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.
Related errors
- Input.Fields[%d].Name %q is not a canonical flag name
- Args field %s (--%s): %w
- Input.Fields references unknown flag --%s
- Invalid column: {column!r}
- Invalid column index: {index}
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/1fa2180306fbfcb9.
Report an issue: GitHub.