Skip to content

Conversation

@welkeyever
Copy link
Member

What type of PR is this?

feat & optimize

Checklists PR title.

  • This PR title matchs the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating user documentation if this PR requires user awareness at the usage level. User docs repo

(Optional) Translate PR title into Chinese.

使用 cobra 重构命令行处理,优化工具使用体验

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
Refactor command-line argument handling from the standard flag package to github.com/spf13/cobra framework.

Key Changes:

  • Replace manual os.Args parsing with cobra's structured subcommand system
  • Migrate all 6 subcommands (parse/write/mcp/agent/init-spec/version) to cobra commands
  • Use StringSliceVar to replace custom StringArray type for multi-value flags
  • Implement MaximumNArgs(1) for optional positional arguments (init-spec)
  • Use PreRunE for parameter validation
  • Maintain 100% backward compatibility with existing CLI interface

Benefits:

  • Cleaner and more maintainable code structure
  • Better help message generation
  • Standardized command-line interface (kubectl/helm pattern)
  • Easier to extend with new subcommands
  • All existing scripts and usages remain unchanged

Testing:

  • Build verification passed (go build -o abcoder .)
  • Backward compatibility verified for all commands
  • Multi-value flags (--exclude, --ts-src-dir) tested

zh:
使用 Go 社区标准命令行工具 cobra 重构 main.go 的命令行处理逻辑。

主要变更:

  • 用 cobra 的子命令系统替代手动的 os.Args 解析
  • 迁移全部 6 个子命令(parse/write/mcp/agent/init-spec/version)到 cobra 命令
  • 使用 StringSliceVar 替代自定义的 StringArray 类型以支持多值标志
  • 实现 MaximumNArgs(1) 支持可选位置参数(init-spec)
  • 使用 PreRunE 进行参数验证
  • 保持 100% 向后兼容性,现有 CLI 接口完全不变

收益:

  • 更清晰、更易维护的代码结构
  • 更好的帮助信息生成
  • 标准化的命令行接口(kubectl/helm 模式)
  • 更容易扩展新的子命令
  • 所有现有脚本和用法保持不变

测试:

  • 构建验证通过(go build -o abcoder .)
  • 全部命令的向后兼容性验证通过
  • 多值标志(--exclude, --ts-src-dir)测试通过

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@welkeyever welkeyever merged commit edc5e25 into main Jan 16, 2026
4 checks passed
@welkeyever welkeyever deleted the optimize/cmd branch January 16, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants