cmd

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package cmd 用 cobra 组织命令行。

Go 小白知识点:

  • cobra 是 Go 生态最流行的命令行库(kubectl、hugo、gh 都用它)。
  • cobra.Command 代表一条命令;Use 是命令名称,Short 是单行简介,Long 是 --help 全文。
  • rootCmd 是「根命令」,所有子命令(如 gen)都挂在它下面,形成命令树。
  • init() 是 Go 的包初始化函数,在 main 运行前自动调用,不可手动调用。 每个 .go 文件可以有自己的 init();同一包内多个 init() 按文件名字母序执行。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute() error

Execute 由 main 调用,启动整个命令树的解析与执行。 cobra.Command.Execute() 内部会:

  1. 解析 os.Args(命令行参数)
  2. 找到对应子命令
  3. 绑定 flags
  4. 调用 RunE / Run 回调

Types

This section is empty.

Jump to

Keyboard shortcuts

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