I'm a Go beginner, and I'm trying to create a CLI with Cobra. To bootstrap the project, I used the Cobra Generator, generated a command, a subcommand, and everything works fine.
I now have this type of layout :
cli
├── cmd
│ ├── command.go
│ ├──…
I am trying to make a Taskfile.yml file for building go application, but I can't quite understand the need of "GOFLAGS=-mod=mod" command before go build main.go.
reference:…
my code
var require bool
cmd.Flags().BoolVarP(&require, "require", "r", true,
"default: true.")
If default value is "true", weather I add "-r" or not, "require" is always "true". But if default value is "false", it works…
I am new to cobra and viper.
I wanted to know if there's a way to exclude flag values that aren't set by the user from cli. So my problem is, I have some optional flags in my cobra cmd that have default values. I wonder if there's a way to exclude…
Im providing command line tool with several command and sub commands, Im using cobra command line and I’ve two separate commands
that first is prerequisite to other
e.g. the first command is preferring the environment by creating temp folder and…
I have a cobra CLI for my own stuff. Now I want to add commonly used executables e.g. kubectl, calicoctl as subcommands which will consume all arguments and flags like
mywrapper kubectl get all --all-namespaces
mywrapper kubectl create deployment…
I have inherited a very large, very old golang codebase. I'm trying to get coverage stats and most of the tests are testing across packages.
If I run go test ./... the tests pass.
If i run go test -coverpkg=./... ./... then the tests fail because…
I have a golang cobra cli app. have configured my vscode for debugging. I want to debug a specific command using vscode for my application.
I am using this launch.json
{
"name": "Launch Package",
"type": "go",
…
I have a CLI with a flag name that I would like to rename, but I would also like to make it so this change is backwards compatible and using the old flag name still works, such as below:
# New flag name
root subcommand --no-color
# Old flag name…
why does the following CLI program using the cobra package throw a stack overflow error when ran with go run /tmp/test.go branch leaf, but does not error when when leaf subcommand is directly connected to root(as commented in the main…
I would like to define a CLI flag that counts the number of times that it appears.
For example, let's define the flag --verbose with its shorthand -v:
# verbose value should be 0
> myCmd
# verbose value should be 1
> myCmd -v
# verbose value…
Hello StackOverflow AWS Gophers,
I'm implementing a CLI with the excellent cobra/viper packages from spf13. We have an Athena database fronted by an API Gateway endpoint, which authenticates with IAM.
That is, in order to interact with its…
I created a Go CLI app with the cobra framework via the cobra add command. After building it with go build it works totally fine if I'm in the repository in the windows cmd. If I click on the .exe I get the following message on a terminal:
This is a…
I'm working on a Cobra-based Go app and I want to have a bash completion for command line flags:
$ my-cool-app --some-id=
The list of valid values for --some-id flag is available by making some HTTP call. How to make such bash completion available…
I noticed that this is perhaps a bug when viper tries to unmarshall to struct. To explain it better, consider this:
I have a cli command like below
dd-cli submit-bug --name "Bug 1" --tag reason1 --tag reason2
Here is my command line source…