pkaramol
pkaramol

Reputation: 19342

Cobra cli fails to initialise new tool

I have an empty dir with a go project, with only go.mod being present (I have run the go mod init command)

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

go 1.13

I would expect that the following command:

▶ ~/go/bin/cobra init mytool

would scaffold the area with boilerplate code so that I start creating my cli tool.

Instead I am getting the following error message:

▶ ~/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)

Why is the package name needed?

Isn't this an issue in the responsibility of go modules ?

Upvotes: 1

Views: 2005

Answers (1)

chmike
chmike

Reputation: 22154

With modules, a package name is required. See the cobra readme.

Upvotes: 3

Related Questions