I am writing a drop-in replacement for an existing tool.
This tool accepts command line options with two arguments:
--arg name value
Is it possible to configure cobra in such way, that it would expect
two values for one argument?
(of course, it is…
I'm new to Golang, and i'm trying out my first CLI application, using the Cobra framework.
My plan is to have few commands, with many flags.
These flags, don't have to have a value attached to them, since they can simply be -r to restart the…
I am using Cobra and want to add a command line flag to the root/top-level command. My init and main function is defined as follows:
func init() {
fmt.Println("init", os.Args)
rootCmd.PersistentFlags().StringP("foo", "f", "", "")
}
func…
I have a cli method that requires one argument with a user provided value, that might contain spaces or other characters that need to be quoted.
My Cobra command is created as follows
command := &cobra.Command{
...
Run: func(cmd…
I have an Azure infrastructure and do not want to release my custom GO cli through Github Actions, I rather want to use an Azure repo and an azure pipeline to build and deploy my go cli which is cross platform. What is the best way possible to…
I have a command with a default option - id. There may be other flags as well, so any of the following could be called.
cmd 81313 # 81313 is the ID
cmd -i 81313
cmd -f foo.txt 81313
cmd -i 81313 -f foo.txt
cmd 81313 -f foo.txt
What is the correct…
I added a new command to my CLI application using the Cobra framework. This command is supposed to start a TCP server that accepts socket connections. It receives a payload which is an absolute path to a file/directory and tries to delete it. Here…
I am working on a new Golang Cobra CLI, which handles several commands. I later on found out that there is already an existing Golang Cobra CLI that handles some commands that I will be covering in the new CLI, but not all. In other words, my new…
I have the following flag addition in a cobra.Cmd
myCmd.PersistentFlags().StringP(applicationLongFlag, applicationShortFlag, applicationDefaultValue, applicationFlagHelpMsg)
Where
applicationLongFlag = "application"
…
I have a cobra command
var mycommandCmd = &cobra.Command{
Use: "mycommand",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
viper.BindPFlags(cmd.Flags())
and a subcommand
var mysubcommandCmd = &cobra.Command{
…
I have the following cobra cli example and I'm trying to make autocomplete to work on my mac.
https://github.com/dharmeshkakadia/cobra-example
If i compile it to a binary called "say" autocomplete work if i'll compile it to any other name it won't…
I have the following configuration model:
type Config struct {
Project []Project `mapstructure:"project"`
}
type Project struct {
Name string `mapstructure:"name"`
}
I want to be able to configure this using a configuration file as well as…
I try this:
projCmd.Flags().StringVarP(&flag, "type", "t", flag, "help")
But, how to implement multiple options with cobra like this:
mycli new -t one -n two
I have the following commands for CLI A (see the real repository):
$ cli-a -h
Usage:
cli-a [command]
Available Commands:
command-a1 command description
command-a2 command description
command-a3 command…
I am using gorilla/mux for the serving my go app. And for the keeping live that http server I am using a channel like that in my server command like in below.
&cobra.Command{
Use: "server",
Run: func(cmd *cobra.Command,…