Ai
1 Star 0 Fork 0

Exi/GO-Makefile 命令简化工具

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
root.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
Exi 提交于 2025-07-10 13:02 +08:00 . v1.0.11
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
// ROOTNAME 主命令名称
const ROOTNAME = "maketools"
// VERSION 版本号
const VERSION = "1.0.11"
// Params
// 参数
type Params struct {
Name string // 参数名称
Shorthand string // 参数缩写
Value string // string 默认值
IntValue int // int 默认值
Usage string // 用法
}
// 注册主命令
var rootCmd = &cobra.Command{
Use: ROOTNAME,
Long: fmt.Sprintf(`%s 用于简化 Makefile 命令的工具(v%s)`, ROOTNAME, VERSION),
Run: func(cmd *cobra.Command, args []string) {},
}
// Execute
// 执行解析入口
func Execute() {
// 关闭 Completion 子命令
rootCmd.CompletionOptions.DisableDefaultCmd = true
// 执行解析
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
// StringP
// 注册字符串参数
func StringP(cmd *cobra.Command, params Params) {
cmd.Flags().StringP(params.Name, params.Shorthand, params.Value, params.Usage)
}
// IntP
// 注册数字参数
func IntP(cmd *cobra.Command, params Params) {
cmd.Flags().IntP(params.Name, params.Shorthand, params.IntValue, params.Usage)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/exi-red/maketools.git
git@gitee.com:exi-red/maketools.git
exi-red
maketools
GO-Makefile 命令简化工具
v1.0.13

搜索帮助