{"record":{"id":"2e0d1cde58e0a2bf","repo":"micro/go-micro","slug":"cannot-use-two-forms-of-the-same-flag-name-ff","errorCode":null,"errorMessage":"Cannot use two forms of the same flag: <name> <ff.Name>","messagePattern":"Cannot use two forms of the same flag: <name> <ff\\.Name>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/source/cli/util.go","lineNumber":34,"sourceCode":"\t}\n}\n\nfunc normalizeFlags(flags []cli.Flag, set *flag.FlagSet) error {\n\tvisited := make(map[string]bool)\n\tset.Visit(func(f *flag.Flag) {\n\t\tvisited[f.Name] = true\n\t})\n\tfor _, f := range flags {\n\t\tparts := f.Names()\n\t\tif len(parts) == 1 {\n\t\t\tcontinue\n\t\t}\n\t\tvar ff *flag.Flag\n\t\tfor _, name := range parts {\n\t\t\tname = strings.Trim(name, \" \")\n\t\t\tif visited[name] {\n\t\t\t\tif ff != nil {\n\t\t\t\t\treturn errors.New(\"Cannot use two forms of the same flag: \" + name + \" \" + ff.Name)\n\t\t\t\t}\n\t\t\t\tff = set.Lookup(name)\n\t\t\t}\n\t\t}\n\t\tif ff == nil {\n\t\t\tcontinue\n\t\t}\n\t\tfor _, name := range parts {\n\t\t\tname = strings.Trim(name, \" \")\n\t\t\tif !visited[name] {\n\t\t\t\tcopyFlag(name, ff, set)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":16,"sourceCodeEnd":51,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/config/source/cli/util.go#L16-L51","documentation":"The CLI config source normalizes flag names (e.g. converting hyphens/underscores or camelCase variants). This error fires when the same flag is registered/visited twice in different textual forms during normalization, which would make the merged config ambiguous. It's a programming/configuration error in the flag set, not a runtime failure.","triggerScenarios":"Registering two flags that normalize to the same canonical name (e.g. \"my-flag\" and \"my_flag\" or \"MyFlag\"), both marked as visited while normalizeFlags walks the flag set; NewSource then rejects the ambiguous set.","commonSituations":"Mixed conventions after merging codebases where one team used hyphens and another underscores; a wrapper library auto-registering aliases for every flag; defining both a shorthand-backed long flag and its long form separately.","solutions":["Remove the duplicate flag registration so each canonical flag name exists only once (keep either \"my-flag\" or \"my_flag\", not both).","If aliases are needed intentionally, register them via the flag package's alias mechanism rather than as separate flags.","Audit flag definitions for names that collide after normalization (lowercase, trimmed, separators collapsed) before building the source.","Pin or update the config library if a dependency auto-generates conflicting aliases (check vendor changelog)."],"exampleFix":"// before\nflag.String(\"db-host\", \"\", \"host\")\nflag.String(\"db_host\", \"\", \"host\") // collides after normalization\n// after\nflag.String(\"db-host\", \"\", \"host\") // single canonical form only","handlingStrategy":"validation","validationCode":"func flagsCollide(names []string) bool {\n    seen := map[string]bool{}\n    for _, n := range names {\n        k := strings.ReplaceAll(strings.ToLower(n), \"_\", \"-\")\n        if seen[k] { return true }\n        seen[k] = true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt one flag naming convention (kebab-case) project-wide","Grep flag registrations in CI for post-normalization collisions","Avoid auto-alias wrappers that register duplicate forms"],"tags":["cli","flags","configuration","duplicate-flag"],"backgroundTag":"duplicate-flag-definition","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}