Questions tagged [cobra]

Three possible technologies: The Cobra toolkit is a pure Java HTML parser and rendering engine with support for CSS 2 and JavaScript. The Cobra Programming Language has Python-like syntax that targets the .NET runtime and supports built-in unit tests, contracts and both dynamic/static programming support. Cobra is a Go library for creating powerful modern CLI applications as well as a program to generate applications and command files.

The Cobra toolkit is a pure Java HTML parser and rendering engine with support for CSS2 and JavaScript.

Cobra can be used as a JavaScript-aware and CSS-aware HTML parser, independently of the Cobra rendering engine. JavaScript DOM modifications that occur during parsing (e.g. via document.write) will be reflected in the parsed DOM, unless JavaScript is disabled.

See also the official homepage.


The Cobra Programming Language has the following features:

  • Clean, high-level syntax
  • Static and dynamic binding
  • First class support for unit tests and contracts
  • Compiled performance with scripting conveniences
  • Lambdas and closures
  • Extensions and mixins

See the homepage.


The Cobra library for Go provides:

  • Easy subcommand-based CLIs: app server, app fetch, etc.
  • Fully POSIX-compliant flags (including short & long versions)
  • Nested subcommands
  • Global, local and cascading flags
  • Easy generation of applications & commands with cobra init appname & cobra add cmdname
  • Intelligent suggestions (app server)
  • Automatic help generation for commands and flags
  • Automatic help flag recognition of -h, --help, etc.
  • Automatically generated bash autocomplete for your application
  • Automatically generated man pages for your application
  • Command aliases so you can change things without breaking them
  • The flexibility to define your own help, usage, etc.
  • Optional tight integration with viper for 12-factor apps

See also the official homepage.

56 questions
1
vote
2 answers

Require a flag as the first argument in a Cobra command

I'm trying to create a Cobra command that uses a flag to inform the action of the command, specifically a configuration command that can either add or remove a configured setting. For example cli> prog_name config --set config_var var_vlue cli>…
NumberOneRobot
  • 1,691
  • 6
  • 17
  • 23
1
vote
1 answer

How to run another command from cobra

I am building a cli app in GoLang . I am using cobra for doing that and I have the following code for that: /* Copyright © 2022 NAME HERE */ package cmd import ( "fmt" "github.com/spf13/cobra" ) // pullCmd represents the…
1
vote
1 answer

Recursively generate golang cobra --help text?

If I have a cobra-managed golang application, I can invoke mycommand --help to see the top level help and list of commands, mycommand cmd1 --help to see the same for the first command, etc. Is there a way using the cobra library to recursively print…
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
1
vote
0 answers

Handle Logrus and Cobra CLI in Golang

I am relatively new to the packages Cobra and Logrus in Golang and there is one little thing I would to ask for help when it comes to integrating them. I am working on a new Golang Cobra CLI which contains several commands/sub-commands. I'd like to…
crileroro
  • 21
  • 1
  • 6
1
vote
0 answers

How can I add a --file (run multiple commands in a file) option to GoLang Cobra app

One of the more popular Linux command line tools (sed) has this option: -f command_file Append the editing commands found in the file command_file to the list of commands. The editing commands should each be listed on a…
Thomas Jay Rush
  • 401
  • 4
  • 12
1
vote
1 answer

Unable to initialize a new package using cobra init --pkg-name demo command in go

cobra init --pkg-name demo Error: unknown flag: --pkg-name Usage: cobra init [path] [flags] Aliases: init, initialize, initialise, create Flags: -h, --help help for init Global Flags: -a, --author string author name for copyright…
Naushad
  • 11
  • 2
1
vote
1 answer

Kubectl like output format for my cobra project

I am new to golang and trying to develop a commandline tool using cobra. I would like to provide flags like kubectl offers to it's users. As a first step i would like to implement kubectl standard format like this kubectl get pods -n mpo NAME …
Jibi Makkar
  • 63
  • 1
  • 8
1
vote
1 answer

Cobra autocomplete without space

I am trying to do dynamic auto-completion in zsh with cobra, and it basically works, but not as I would like. The argument is passed to a function for auto-completion only after a space, but there is a need to enable auto-completion without a…
simak92
  • 11
  • 1
1
vote
1 answer

Named Positional Arguments in Cobra

I have the following Cobra sub-command: package stripeCommands import ( "fmt" "cmd/cliConstants" "github.com/spf13/cobra" "log" ) var ( deleteCustomerCommand = &cobra.Command{ Use: "delete", Short: …
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
1
vote
1 answer

Casting pflags.Flag.Value as Arbitrary Types

I am using github.com/spf13/cobra to parse command-line flags and just about everything I'm doing is working well, but I'm having trouble figuring out how to get a specifically typed value out of a *cobra.Command at runtime. My command definition…
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
1
vote
1 answer

How to call SetOut() on subcommands in Cobra?

I am trying to test my CLI application written with Cobra, specifically to test if subcommands are writing correctly to STDOUT. For this, I try to redirect the output from STDOUT to my buffer. Unfortunately, for whatever reason, the SetOut()…
Petr
  • 486
  • 7
  • 19
1
vote
1 answer

How to unit test a Cobra CLI command which requires internal mocks?

I have defined the following Cobra subcommand that I'd like to test the output for using testify: var childCmd = &cobra.Command{ Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { id := args[0] …
vercingortix
  • 199
  • 2
  • 15
1
vote
3 answers

Python: Most elegant way to merge two dictionaries with the same key

I am working on genome-scale models and trying to create a minimal medium that suits two optimal flux conditions. I get two dictionaries with the required medium components looking like this: EX_C00001_ext_b 1.132993 EX_C00011_ext_b …
Mibi
  • 288
  • 1
  • 10
1
vote
0 answers

Why Gtk examples run under one language but not other

I have installed Csharp and Gtk (both 2 and 3) in Debian Stable Linux and I am trying to run a gtk example code file present in folder /usr/share/gtk-sharp2-examples/ . This simple file contains: // HelloWorld.cs - GTK Window class Test…
rnso
  • 23,686
  • 25
  • 112
  • 234
1
vote
1 answer

Failure to import plot_helper in CobraPy

I am trying to do this tutorial for CobraPy and can't seem to get plot_helper to import Where is plot_helper? Is it a pip download?