go config_error ai_generated true

标志重复定义:-name

flag redefined: -name

ID: go/flag-redefined

其他格式: JSON · Markdown 中文 · English
87%修复率
84%置信度
1证据数
2024-06-01首次发现

版本兼容性

版本状态引入弃用备注
Go 1.18 active
Go 1.19 active
Go 1.20 active

根因分析

通过flag包注册了相同的标志名称,通常是由于导入了两个定义相同标志的包,或在多个地方使用相同的名称调用flag.StringVar。

English

The same flag name is registered twice via the flag package, typically due to importing two packages that define the same flag or calling flag.StringVar with the same name in multiple places.

generic

官方文档

https://pkg.go.dev/flag#Var

解决方案

  1. Define all flags in the main function or a single initialization function, and call flag.Parse() only once
  2. Use flag.NewFlagSet to create separate flag sets for different packages or components

无效尝试

常见但无效的做法:

  1. 50% 失败

    This may break command-line interface consistency or cause confusion if the flag has a standard meaning.

  2. 70% 失败

    The underlying cause (duplicate registration) still exists; pflag may also panic on duplicate definitions.