Cobra is a Golang package that provides a simple interface to create command line programs. At the same time, Cobra is also an application that is used to generate application frameworks to develop applications based on Cobra.
Use cobra init
the command to initialize framework, but found an error:
Error: required flag(s) " pkg-name " not set
After checking the official documentation, I found that after the Cobra version is updated, a mandatory parameter needs to be added --pkg-name
, which is the package imported by the main function by default.
Updates to the Cobra generator have now decoupled it from the GOPATH. As such
--pkg-name
is required.
So use the following command to initialize:
Create the directory cobra_demo first, enter and then initialize
cobra init --pkg-name cobra_demo
After the initialization is successful, the following prompt message appears:
Your Cobra application is ready at
At this time, the project structure should be as follows:
cobra_demo/ cmd / root.go main.go LICENSE
Read More:
- [Solved] ambiguous import: found package github.com/spf13/cobra/cobra in multiple modules
- [Solved] Fabric_sdk_go:QueryBlockConfig failed: QueryBlockConfig failed: target(s) required
- Go declares that the local variable does not use command line arguments. Main. Go: 4:6: a declared but not used
- K8s Install Error: Error: unknown flag: –experimental-upload-certs
- [Solved] Golang Error: main.go:5:2: package go_code/chapter10/factory/model is not in GOROOT
- K8S error validating data: ValidationError(Deployment.spec): missing required field selector
- [Solved] Error running ‘go build myfir_go_project‘: Cannot run program
- [Solved] Go Get Download Dependency Error: is not using a known version control system
- [Solved] .\main.go:3:6: missing function body .\main.go:4:1: syntax error: unexpected semicolon or newline be
- Docker run Error: container_linux.go:235: starting container process caused “process_linux.go:258: appl
- [Solved] cannot find package “go.opentelemetry.io/otel/api/trace“ in any of
- vscode: Error loading workspace: err: exit status 1: stderr: build flag -mod=readonly only valid
- k8s kubernetes ingress error: endpoints “default-http-backend“ not found
- [Solved] Goland sdk Error: The selected directory is not a valid home for Go SDK
- [Solved] “Field pet in XXX.HelloController required a bean of type ‘XXX.Pet‘ that could not be found.“
- GO Exception Runnerw.exe: CreateProcess failed with error 21
- [Local Precompilation Error] do not set execute permissions for source files
- [Solved] VScode Error: build constraints exclude all Go files in syscall\js
- [Solved] hcitool Error: Set scan parameters failed: Operation not permitted
- K8S Master Initialize Error: [ERROR CRI]: container runtime is not running: output: E0812