In the following code I'm defining a command, where two options are possible:
1. myapp info --flag1 text
2. myapp info --flag2
if none of the two options are specified, I want to show the helpCommand
var infoCmd = &cobra.Command{
Use: …
I'm very new to Go in general, and this is my first project in Cobra.
It seems easy enough to create commands in Cobra with the command-line tool:
cobra add
And adding sub-commands seems easy enough as well.
cobra add -p…
In GO's Cobra, lib for making CLIs, there are two input flags accepting multiple values being passed. One of the options is StringArray, when used as follows:
--flag=value1 --flag=value2
it yields an array ["value1", "value2"].
I am working on a…
I am creating a client with the Cobra framework in Go that consists of uploading a file to a transfer service that will be released very soon.
I want it to be a minimally customizable with a default download folder.
Problem when I want to check that…
is there a way of dynamically registering cobra commands based on a viper configuration file? Basically I want to only register commands that are available within my config file as "modules".
My root.go's init function looks like this
func init() {
…
I'm trying to get autocomplete working with Cobra but nothing happens after pressing the tab key - on something that I think should autocomplete. Am I missing something?
var HelloCmd = &cobra.Command{
Use: "hello ",
Short: "Say hello…
I have the following cobra setup
var rootCmd = &cobra.Command{
Use: "basic",
Short: "This is the basic command",
PreRunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
…
I am using cobra to create a CLI application (app). I need to implement a behavior in which I can pass flags as arguments. These flags will be passed|used further to another application via exec.Command(). All flag arguments passed to app must be…
I'm building a CLI using Go and Cobra library. I've the following JSON that needs to be deserialized in the corresponding struct.
Argument as JSON array:
"[
(stringA, stringB),
stringC
]"
Struct
type MyStruct struct {
StringArray…
I want the user of my CLI app to enter a specific path where they want to save files.
I tried to use Cobra's --config flag but I don't know how to.
Example:
app --config path "~/Documents/"
How could I do this?
I'm working with the Cobra library for Go. The README shows an example that handles configuration setup via the cobra.OnInitialize function. The documentation for OnInitialize says:
OnInitialize sets the passed functions to be run when each…
Cobra CLI has support for PostRun to invoke after execution of a command.
https://github.com/spf13/cobra#prerun-and-postrun-hooks
How do I pass on the command status to PostRun call?
I have requirement of posting the command status after its…
I am using a StringSliceP from the Pflag libraray accept a list of strings as CLI arguments.
I am calling the Go application from the Windows Command Prompt.
I would like some of the strings of the list to contain a (") double quote character, but I…
I have the following code, is really simple. The point is that the code after the first fmt.Println is never executed. Any idea why?
The code creates a random string, and then creates a Gin Router. The code that executes the router is never being…
I want to use spf13/cobra on my project.
spf13/cobra: A Commander for modern Go CLI interactions
typed install command result
$ go get -u github.com/spf13/cobra/cobra
go: downloading github.com/spf13/cobra v1.0.0
go: downloading…