# 提供了标志但未定义：-foo

- **ID:** `go/flag-provided-but-not-defined`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 97%

## 根因

向 Go 程序传递的命令行标志没有使用 flag 包进行相应的标志定义。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## 解决方案

1. ```
   在解析前定义标志：var foo string; flag.StringVar(&foo, "foo", "", "用法"); flag.Parse()
   ```
2. ```
   如果标志来自第三方工具，请查阅其文档并添加正确的标志定义
   ```
3. ```
   使用 flag.VisitAll() 列出所有已定义的标志，并验证预期的标志是否存在
   ```

## 无效尝试

- **Change the flag name in the command line to match an existing flag** — May not be the intended flag; could cause incorrect behavior if the wrong flag is used (50% 失败率)
- **Ignore the error and continue execution by catching it** — flag.Parse() terminates on undefined flags; cannot be ignored (95% 失败率)
- **Use a third-party flag library that doesn't report this error** — Switching libraries may introduce compatibility issues and doesn't fix the missing definition (60% 失败率)
