go-cobra Questions
4
Solved
I am following this guide.
***@pop-os:~/go/src/foo$ cobra init --pkg-name foo
Command 'cobra' not found, but can be installed with:
sudo apt install cobra
My setup:
I have go 1.16 installed
$ go v...
3
Using cobra, if my app is invoked without a specific action (but arguments), I'd like to run a default command:
// rootCmd represents the base command when called without any subcommands
var rootC...
1
Solved
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 typ...
3
Is there built-in tooling (and if so how do I use it?) to require a flag to be one of several values and throw an error if a flag is not one of the permitted values, in the Cobra library? I didn't ...
2
Solved
I'm trying to figure out whats is the difference between PersistentFlags and Flags in go-Cobra, and when should we use each of them.
I've read this but I didn't understand it.
1
Solved
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: https://dev.to...
2
I'm developing some CLI utility with Cobra. For my RootCmd I've set up some persistent flags (i.e. flags which also affect all the commands). But some of the commands don't use those flags, so I'd ...
3
Solved
I want sub command to print out the help menu if no argument or flags are passed (The main command does this by default).
For example, the main command without any arguments or flags:
chris@pop-os:...
1
Solved
my code
var require bool
cmd.Flags().BoolVarP(&require, "require", "r", true,
"default: true.")
If default value is "true", weather I add "-r&...
4
Solved
The documentation in Cobra and Viper are confusing me. I did cobra init fooproject and then inside the project dir I did cobra add bar. I have a PersistentFlag that is named foo and here is the ini...
3
Solved
I've just recently started working with Go, and I've run into some
behavior working with Cobra and Viper that I'm not sure I understand.
This is a slightly modified version of the sample code you g...
1
Solved
The sketch below is a command line application written using Cobra and Go. I'd like to throw an error if the value of flag1 doesn't match the regex ^\s+\/\s+. How do I do that?
package cmd
import ...
1
Solved
I'm maintaining some code written using Go (golang), Viper and Cobra.
On one line, it has:
rootCmd.PersistentFlags().String("cfg", "", "A description")
And then on th...
2
Solved
I'm starting a new OSS CLI tool that utilizes spf13/cobra. Being new to golang, I'm having a hard time figuring out the best way to test commands in isolation. Can anybody give me an example of how...
Moorer asked 13/1, 2020 at 0:29
1
Solved
I want to be able to set the Usage line to specify that an argument NEEDS to be passed if the help function is invoked on the cobra command in Go.
This is what the regular help flag outputs:
Canc...
Thera asked 8/2, 2019 at 0:3
1
Solved
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 ...
1
Solved
I have this following config file defined as toml file:
[staging]
project-id = "projectId"
cluster-name = "cluster"
zone = "asia-southeast1-a"
Then, I have this struct
type ConfigureOpts struc...
1
Solved
I'm using cobra to build a CLI and want to simulate a command being run with different sets of options/flags. I've been trying to figure out how I can use the cobra APIs to set flags within my test...
Obsess asked 16/4, 2018 at 2:35
2
Solved
I want to create Golang CLI with Cobra. For now, it runs well. I have created something like foobar create --username johndoe. But I need subcommands like foobar create user --username johndoe. The...
1
Solved
Basic information: I have created a go application and used Cobra for it. Cobra uses Viper for command line parameters and flags.
I have a command listen with a flag bind and I want to configure i...
1
© 2022 - 2024 — McMap. All rights reserved.