登录
首页 >  Golang >  Go问答

Cobra CLI 无法创建新工具

来源:stackoverflow

时间:2024-03-04 15:12:26 366浏览 收藏

一分耕耘,一分收获!既然打开了这篇文章《Cobra CLI 无法创建新工具》,就坚持看下去吧!文中内容包含等等知识点...希望你能在阅读本文后,能真真实实学到知识或者帮你解决心中的疑惑,也欢迎大佬或者新人朋友们多留言评论,多给建议!谢谢!

问题内容

我有一个包含 go 项目的空目录,仅存在 go.mod (我已运行 go mod init 命令)

▶ cat go.mod
module github.com/myorganization/mytool

go 1.13

我期望以下命令:

▶ ~/go/bin/cobra init mytool

将使用样板代码搭建该区域,以便我开始创建我的 cli 工具。

相反,我收到以下错误消息:

▶ ~/go/bin/cobra init mytool
Error: required flag(s) "pkg-name" not set
Usage:
  cobra init [name] [flags]

Aliases:
  init, initialize, initialise, create

Flags:
  -h, --help              help for init
      --pkg-name string   fully qualified pkg name

Global Flags:
  -a, --author string    author name for copyright attribution (default "YOUR NAME")
      --config string    config file (default is $HOME/.cobra.yaml)
  -l, --license string   name of license for the project
      --viper            use Viper for configuration (default true)

为什么需要包名?

这不是go模块的责任问题吗?


解决方案


对于模块,需要包名称。参见cobra readme

今天关于《Cobra CLI 无法创建新工具》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>