cli

module
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT

README

GitCode CLI

Go Version License Release

GitCode 命令行工具,为 GitCode 用户提供便捷的命令行操作体验。

安装

从源码构建

前置要求:

  • Go 1.22+
# 克隆仓库
git clone https://gitcode.com/gitcode-cli/cli.git
cd cli

# 构建
go build -o gc ./cmd/gc

# 安装到用户目录
mkdir -p ~/.local/bin
mv gc ~/.local/bin/
export PATH="$HOME/.local/bin:$PATH"
Linux 包管理器

DEB (Debian/Ubuntu):

# 从 Releases 下载 .deb 包
wget https://gitcode.com/gitcode-cli/cli/releases/download/v0.2.7/gc_0.2.7_amd64.deb

# 安装
sudo dpkg -i gc_0.2.7_amd64.deb

RPM (RHEL/CentOS/Fedora):

# 从 Releases 下载 .rpm 包
wget https://gitcode.com/gitcode-cli/cli/releases/download/v0.2.7/gc-0.2.7-1.x86_64.rpm

# 安装
sudo rpm -i gc-0.2.7-1.x86_64.rpm
规划中的安装方式

以下安装方式正在开发中:

  • 预编译二进制文件(Linux/macOS/Windows)
  • Homebrew (macOS/Linux)
  • Scoop (Windows)
  • Docker 镜像

快速开始

认证

方式一:设置环境变量(推荐)

# 设置 Token 环境变量
export GC_TOKEN="your_gitcode_token"

# 或使用备用变量名
export GITCODE_TOKEN="your_gitcode_token"

# 添加到 shell 配置文件(永久生效)
echo 'export GC_TOKEN="your_gitcode_token"' >> ~/.bashrc
source ~/.bashrc

方式二:交互式登录

# 交互式登录(需输入 Token)
gc auth login

# 使用 Token 参数登录
gc auth login --token YOUR_TOKEN

获取 Token:

  1. 登录 GitCode
  2. 进入 设置 -> 私人令牌
  3. 点击"生成新令牌",选择所需权限
  4. 复制生成的 Token

验证认证:

# 查看认证状态
gc auth status

📖 完整命令指南: 查看 COMMANDS.md 获取所有命令的详细使用说明和示例。

命令示例

仓库操作
# 克隆仓库
gc repo clone owner/repo

# 创建新仓库
gc repo create my-repo --public

# 查看仓库信息
gc repo view owner/repo

# Fork 仓库
gc repo fork owner/repo

# 删除仓库
gc repo delete owner/repo
Issue 管理
# 创建 Issue
gc issue create --title "Bug report" --body "Description"

# 列出 Issues
gc issue list --state open

# 查看 Issue 详情
gc issue view 123

# 关闭 Issue
gc issue close 123

# 重开 Issue
gc issue reopen 123

# 添加评论
gc issue comment 123 --body "Comment text"

# 管理 Issue 标签
gc issue label 123 --add bug,enhancement
Pull Request 管理
# 创建 PR(自动检测当前分支)
gc pr create --title "New feature" --base main

# 创建跨仓库 PR(从 fork 到 upstream)
gc pr create -R upstream/repo --fork myfork/repo --title "Feature"

# 列出 PR
gc pr list --state open

# 查看 PR 详情
gc pr view 456

# 检出 PR 分支
gc pr checkout 456

# 合并 PR
gc pr merge 456 --squash

# 关闭/重开 PR
gc pr close 456
gc pr reopen 456

# 编辑 PR
gc pr edit 456 --title "New title"
gc pr edit 456 --draft true

# 代码检视
gc pr review 456 --approve
gc pr review 456 --request
gc pr review 456 --comment "Review comment"
Release 管理
# 创建 Release(建议包含 --notes 参数)
gc release create v1.0.0 --title "Version 1.0" --notes "Release notes"

# 列出 Releases
gc release list -R owner/repo

# 查看 Release 详情
gc release view v1.0.0 -R owner/repo

# 上传资产到 Release
gc release upload v1.0.0 app.zip -R owner/repo
gc release upload v1.0.0 file1.tar.gz file2.rpm -R owner/repo

# 下载 Release 资产
gc release download v1.0.0 -R owner/repo
gc release download v1.0.0 app.zip -R owner/repo -o ./downloads/

# 删除 Release
gc release delete v1.0.0 -R owner/repo

注意: release create 命令建议包含 --notes 参数,否则可能返回错误。

功能特性

功能 描述
🔐 认证管理 Token 认证、多账户支持、安全存储
📦 仓库操作 克隆、创建、Fork、查看、删除
🐛 Issue 管理 创建、列表、查看、关闭、重开、评论
🔀 PR 管理 创建、列表、查看、检出、合并、关闭
👀 代码检视 批准、请求修改、添加评论
🏷️ 标签管理 创建、列表、删除
🎯 里程碑管理 创建、列表、查看、删除
🚀 Release 管理 创建、列表、查看、上传资产、下载资产

命令概览

gc <command> <subcommand> [flags]

Commands:
  auth        认证管理 (login, logout, status, token)
  repo        仓库操作 (clone, create, list, view, fork, delete)
  issue       Issue 管理 (create, list, view, close, reopen, comment)
  pr          PR 管理 (create, list, view, checkout, merge, close, reopen, review, diff, ready)
  label       标签管理 (create, list, delete)
  milestone   里程碑管理 (create, list, view, delete)
  release     Release 管理 (create, list, view, upload, download, delete)
  version     显示版本信息

配置

配置文件位置: ~/.config/gc/config.yaml

# 默认主机
host: gitcode.com

# Git 协议
git_protocol: https

# 默认编辑器
editor: vim

# 分页器
pager: less
环境变量
变量 描述
GC_TOKEN 认证 Token
GITCODE_TOKEN 备用 Token
GC_HOST 默认主机
NO_COLOR 禁用颜色输出

Shell 补全

# Bash
gc completion bash > /etc/bash_completion.d/gc
source ~/.bashrc

# Zsh
gc completion zsh > "${fpath[1]}/_gc"
source ~/.zshrc

# Fish
gc completion fish > ~/.config/fish/completions/gc.fish
source ~/.config/fish/config.fish

文档

技术栈

组件 技术
语言 Go 1.22+
命令框架 Cobra
配置格式 YAML
目标平台 Linux, macOS, Windows

开发

# 克隆仓库
git clone https://gitcode.com/gitcode-cli/cli.git
cd gitcode-cli

# 安装依赖
make deps

# 构建
make build

# 运行测试
make test

# 代码检查
make lint

# 运行
make run

贡献

欢迎贡献代码!请查看 贡献指南

许可证

MIT License

致谢

本项目参考了 GitHub CLI 的设计与实现,感谢 GitHub 团队的开源贡献。

相关链接

Directories

Path Synopsis
Package api provides GitCode API client
Package api provides GitCode API client
cmd
gc command
Package main is the entry point for gitcode-cli
Package main is the entry point for gitcode-cli
Package git provides Git operations for gitcode-cli
Package git provides Git operations for gitcode-cli
internal
config
Package config provides configuration management for gitcode-cli
Package config provides configuration management for gitcode-cli
pkg
browser
Package browser provides utilities for opening URLs in a web browser
Package browser provides utilities for opening URLs in a web browser
cmd/auth
Package auth implements authentication commands
Package auth implements authentication commands
cmd/auth/login
Package login implements the auth login command
Package login implements the auth login command
cmd/auth/logout
Package logout implements the auth logout command
Package logout implements the auth logout command
cmd/auth/status
Package status implements the auth status command
Package status implements the auth status command
cmd/auth/token
Package token implements the auth token command
Package token implements the auth token command
cmd/issue
Package issue implements the issue command
Package issue implements the issue command
cmd/issue/close
Package close implements the issue close command
Package close implements the issue close command
cmd/issue/comment
Package comment implements the issue comment command
Package comment implements the issue comment command
cmd/issue/create
Package create implements the issue create command
Package create implements the issue create command
cmd/issue/label
Package label implements the issue label command
Package label implements the issue label command
cmd/issue/list
Package list implements the issue list command
Package list implements the issue list command
cmd/issue/reopen
Package reopen implements the issue reopen command
Package reopen implements the issue reopen command
cmd/issue/view
Package view implements the issue view command
Package view implements the issue view command
cmd/label
Package label implements the label command
Package label implements the label command
cmd/label/create
Package create implements the label create command
Package create implements the label create command
cmd/label/delete
Package delete implements the label delete command
Package delete implements the label delete command
cmd/label/list
Package list implements the label list command
Package list implements the label list command
cmd/milestone
Package milestone implements the milestone command
Package milestone implements the milestone command
cmd/milestone/create
Package create implements the milestone create command
Package create implements the milestone create command
cmd/milestone/delete
Package delete implements the milestone delete command
Package delete implements the milestone delete command
cmd/milestone/list
Package list implements the milestone list command
Package list implements the milestone list command
cmd/milestone/view
Package view implements the milestone view command
Package view implements the milestone view command
cmd/pr
Package pr implements the pr command
Package pr implements the pr command
cmd/pr/checkout
Package checkout implements the pr checkout command
Package checkout implements the pr checkout command
cmd/pr/close
Package close implements the pr close command
Package close implements the pr close command
cmd/pr/comments
Package comments implements the pr comments command
Package comments implements the pr comments command
cmd/pr/create
Package create implements the pr create command
Package create implements the pr create command
cmd/pr/diff
Package diff implements the pr diff command
Package diff implements the pr diff command
cmd/pr/edit
Package edit implements the pr edit command
Package edit implements the pr edit command
cmd/pr/list
Package list implements the pr list command
Package list implements the pr list command
cmd/pr/merge
Package merge implements the pr merge command
Package merge implements the pr merge command
cmd/pr/ready
Package ready implements the pr ready command
Package ready implements the pr ready command
cmd/pr/reopen
Package reopen implements the pr reopen command
Package reopen implements the pr reopen command
cmd/pr/review
Package review implements the pr review command
Package review implements the pr review command
cmd/pr/test
Package test implements the pr test command
Package test implements the pr test command
cmd/pr/view
Package view implements the pr view command
Package view implements the pr view command
cmd/release
Package release implements the release command
Package release implements the release command
cmd/release/create
Package create implements the release create command
Package create implements the release create command
cmd/release/delete
Package delete implements the release delete command
Package delete implements the release delete command
cmd/release/download
Package download implements the release download command
Package download implements the release download command
cmd/release/edit
Package edit implements the release edit command
Package edit implements the release edit command
cmd/release/list
Package list implements the release list command
Package list implements the release list command
cmd/release/upload
Package upload implements the release upload command
Package upload implements the release upload command
cmd/release/view
Package view implements the release view command
Package view implements the release view command
cmd/repo
Package repo implements repository commands
Package repo implements repository commands
cmd/repo/clone
Package clone implements the repo clone command
Package clone implements the repo clone command
cmd/repo/create
Package create implements the repo create command
Package create implements the repo create command
cmd/repo/delete
Package delete implements the repo delete command
Package delete implements the repo delete command
cmd/repo/fork
Package fork implements the repo fork command
Package fork implements the repo fork command
cmd/repo/list
Package list implements the repo list command
Package list implements the repo list command
cmd/repo/view
Package view implements the repo view command
Package view implements the repo view command
cmd/root
Package root implements the root command for gc
Package root implements the root command for gc
cmd/version
Package version implements the version command
Package version implements the version command
cmdutil
Package cmdutil provides utilities for command implementation
Package cmdutil provides utilities for command implementation
iostreams
Package iostreams provides input/output stream management
Package iostreams provides input/output stream management

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL