Questions tagged [go-cobra]

A Commander for modern Go CLI interactions

A Commander for modern Go CLI interactions (https://github.com/spf13/cobra)

125 questions
0
votes
0 answers

How to pass two values for an option in Cobra?

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…
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
0
votes
1 answer

Golang Cobra multiple flags with no value

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…
0
votes
0 answers

How to parse command line in Execute function within Cobra?

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…
HelloWorld
  • 2,392
  • 3
  • 31
  • 68
0
votes
0 answers

Cobra ValidArgsFunction for items with spaces?

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…
bart van deenen
  • 661
  • 6
  • 16
0
votes
0 answers

GO cli on Azure Artifacts

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…
0
votes
1 answer

Using no flag options with Cobra Command?

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…
aronchick
  • 6,786
  • 9
  • 48
  • 75
0
votes
1 answer

`no such file or directory` with `os.Remove` inside go routine

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…
hoomz
  • 3
  • 1
0
votes
1 answer

Link another Golang Cobra CLI to current Golang Cobra CLI

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…
jtee
  • 79
  • 8
0
votes
1 answer

cobra failing to mark flag as required

I have the following flag addition in a cobra.Cmd myCmd.PersistentFlags().StringP(applicationLongFlag, applicationShortFlag, applicationDefaultValue, applicationFlagHelpMsg) Where applicationLongFlag = "application" …
pkaramol
  • 16,451
  • 43
  • 149
  • 324
0
votes
1 answer

PreRun / PreRunE hooks not being executed in cobra

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{ …
pkaramol
  • 16,451
  • 43
  • 149
  • 324
0
votes
1 answer

Why does cobra autocomplete isn't working?

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…
0
votes
1 answer

How can I use Cobra and Viper to bind a value as the first item in an array in the configuration?

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…
Russell Seymour
  • 1,333
  • 1
  • 16
  • 35
0
votes
1 answer

How to implement multiple options with cobra

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
null
  • 115
  • 1
  • 9
0
votes
1 answer

How to combine two Cobra CLIs into one?

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…
Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
0
votes
0 answers

How to keep live server command with channel

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,…
Cem Ezgin
  • 37
  • 8
1 2 3
8 9