fix: NO_COLOR does not win over CLICOLOR_FORCE under --color=auto

未关闭 适合新手
#110 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go, shell
领域
cli

调研方向

从 internal/cli/colorflag.go 开始:文中所述的优先级位于第 101-103 行,rewriteEnviron 中的 NO_COLOR 重写位于第 115-135 行,第 155-168 行附近的处理逻辑也需要关注。修复方法是在 --color=auto 下且 NO_COLOR 非空时,在 colorprofile 读取之前从环境中删除 CLICOLOR_FORCE。使用 NO_COLOR=1 CLICOLOR_FORCE=1 codegraph version | cat -v 复现问题,然后为该输入添加一个测试,断言 ESC 字节数为零,该测试在当前代码上应当失败。

由索引模型根据 Issue 内容生成。

描述

bug priority:low
What happens
$ NO_COLOR=1 CLICOLOR_FORCE=1 codegraph version | cat -v
^[[1;38;2;95;215;255mcodegraph dev^[[m ^[[2;38;2;147;161;161m(commit unknown, built unknown)^[[m ...

Under --color=auto, rewriteEnviron rewrites NO_COLOR to NO_COLOR=1 but passes CLICOLOR_FORCE through unchanged, and colorprofile lets CLICOLOR_FORCE win.

What you expected instead

No escape bytes. The code's stated order is NO_COLOR > CLICOLOR_FORCE > CLICOLOR=0 > TTY.

Steps to reproduce

Run the command above with any build of main.

Version

main at d384473e (built locally, codegraph dev)

Platform

macOS 27 arm64

How did you install it?

Built from source

Evidence
  • internal/cli/colorflag.go:101-103 (stated order), :115-135 (NO_COLOR rewritten, CLICOLOR_FORCE kept), :155-168
Acceptance criteria
  • With a non-empty NO_COLOR, --color=auto drops CLICOLOR_FORCE before colorprofile sees it.
  • A test covering NO_COLOR=1 CLICOLOR_FORCE=1 asserts zero ESC bytes, and fails on the current code.

Source (GSD planning files, archived at d384473e): .planning/milestones/v0.14.0-MILESTONE-AUDIT.md (T-04-30)


🤖 Generated with Claude Code

https://claude.ai/code/session_01UNqdnC3q6U362BvyfxuKCF

主要语言
Go
星标
0
派生
0
平均合并
5 小时 16 分钟
30 天内合并 PR
107

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

seanb4t/codegraph-go 的其他 Issue

查看 seanb4t/codegraph-go 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。