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...
Conceptualism asked 5/4, 2021 at 11:44

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...
Niobium asked 29/7, 2019 at 18:43

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...
Engenia asked 7/10, 2022 at 11:27

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 ...
Barcroft asked 12/6, 2018 at 19:33

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.
Seduce asked 19/8, 2020 at 22:51

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...
Varico asked 15/2, 2022 at 5:49

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 ...
Eldred asked 5/10, 2017 at 17:7

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:...
True asked 7/3, 2018 at 9:59

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&...
Parma asked 30/7, 2021 at 3:24

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...
Buckwheat asked 8/5, 2017 at 12:32

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...
Flyblown asked 28/5, 2021 at 16:25

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 ...
Furriery asked 22/4, 2021 at 17:40

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...
Bordure asked 10/8, 2020 at 13:17

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 ...
Querulous asked 9/7, 2018 at 13:11

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...
Jane asked 8/7, 2018 at 2:35

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...
Ferebee asked 6/11, 2017 at 5:31

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...
Recess asked 10/1, 2017 at 20:56
1

© 2022 - 2024 — McMap. All rights reserved.