代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。