Skip to content
Myr

README.md

This file

Path

README.md

111 lines · 4.3 KiB · Markdown

Last changed by

Changed branch name in the cobra generator link to 'main' (#1645)Neville Bokdawallabefore adoptiond622355

History of this file

Take it

The walk stopped after 200 commits: lines older than 0ea93dd point at it.

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 1–2why, one step back
1![cobra logo](https://cloud.githubusercontent.com/assets/173412/10886352/ad566232-814f-11e5-9cd0-aa101788c117.png)
2

Removes viper dependency by removing cobra/ CLI tool (#1604)John McBridebefore adoption5b2b9e9

line 3why, one step back
3Cobra is a library for creating powerful modern CLI applications.

Fixed linter issuesJuan Lenibefore adoption0ea93dd

line 4why, one step back
4

Move projects using Cobra (#1090)Warren Fernandesbefore adoption090d94f

lines 5–7why, one step back
5Cobra is used in many Go projects such as [Kubernetes](http://kubernetes.io/),
6[Hugo](https://gohugo.io), and [Github CLI](https://github.com/cli/cli) to7name a few. [This list](./projects_using_cobra.md) contains a more extensive list of projects using Cobra.

Fixed linter issuesJuan Lenibefore adoption0ea93dd

line 8why, one step back
8

ci: add GitHub Actions workflow 'Test' (#1339)Unai Martinez-Corralbefore adoptionb73b344

line 9why, one step back
9[![](https://img.shields.io/github/workflow/status/spf13/cobra/Test?longCache=tru&label=Test&logo=github%20actions&logoColor=fff)](https://github.com/spf13/cobra/actions?query=workflow%3ATest)

Update Go Doc link and badge (#1593)Marian Steinbachbefore adoption7cabfeb

line 10why, one step back
10[![Go Reference](https://pkg.go.dev/badge/github.com/spf13/cobra.svg)](https://pkg.go.dev/github.com/spf13/cobra)

add goreportcard to readme (#971)Joshua Harshmanbefore adoption3745fcd

line 11why, one step back
11[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/cobra)](https://goreportcard.com/report/github.com/spf13/cobra)

Add slack badge to point to cobra slack channel (#1181)Warren Fernandesbefore adoption0e27f22

line 12why, one step back
12[![Slack](https://img.shields.io/badge/Slack-cobra-brightgreen)](https://gophers.slack.com/archives/CD3LP1199)

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 13–26why, one step back
13
14# Overview1516Cobra is a library providing a simple interface to create powerful modern CLI17interfaces similar to git & go tools.1819Cobra provides:20* Easy subcommand-based CLIs: `app server`, `app fetch`, etc.21* Fully POSIX-compliant flags (including short & long versions)22* Nested subcommands23* Global, local and cascading flags24* Intelligent suggestions (`app srver`... did you mean `app server`?)25* Automatic help generation for commands and flags26* Automatic help flag recognition of `-h`, `--help`, etc.

Extend Go completions and revamp zsh comp (#1070) (#1070)Marc Khouzambefore adoption2c5a0d3

line 27why, one step back
27* Automatically generated shell autocomplete for your application (bash, zsh, fish, powershell)

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 28–30why, one step back
28* Automatically generated man pages for your application
29* Command aliases so you can change things without breaking them30* The flexibility to define your own help, usage, etc.

Update documentation to reflect the module aware generatorSteve Franciabefore adoptionc97b7ec

line 31why, one step back
31* Optional seamless integration with [viper](http://github.com/spf13/viper) for 12-factor apps

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 32–38why, one step back
32
33# Concepts3435Cobra is built on a structure of commands, arguments & flags.3637**Commands** represent actions, **Args** are things and **Flags** are modifiers for those actions.38

README.md Readability Improvements (#1228)zaataylorbefore adoption39b5a91

lines 39–40why, one step back
39The best applications read like sentences when used, and as a result, users
40intuitively know how to interact with them.

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 41–64why, one step back
41
42The pattern to follow is43`APPNAME VERB NOUN --ADJECTIVE.`44 or45`APPNAME COMMAND ARG --FLAG`4647A few good real world examples may better illustrate this point.4849In the following example, 'server' is a command, and 'port' is a flag:5051 hugo server --port=13135253In this command we are telling Git to clone the url bare.5455 git clone URL --bare5657## Commands5859Command is the central point of the application. Each interaction that60the application supports will be contained in a Command. A command can61have children commands and optionally run an action.6263In the example above, 'server' is the command.64

Updating generator documentation and linksSteve Franciabefore adoptioncf87fc4

line 65why, one step back
65[More about cobra.Command](https://pkg.go.dev/github.com/spf13/cobra#Command)

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 66–81why, one step back
66
67## Flags6869A flag is a way to modify the behavior of a command. Cobra supports70fully POSIX-compliant flags as well as the Go [flag package](https://golang.org/pkg/flag/).71A Cobra command can define flags that persist through to children commands72and flags that are only available to that command.7374In the example above, 'port' is the flag.7576Flag functionality is provided by the [pflag77library](https://github.com/spf13/pflag), a fork of the flag standard library78which maintains the same interface while adding POSIX compliance.7980# Installing81Using Cobra is easy. First, use `go get` to install the latest version

Removes viper dependency by removing cobra/ CLI tool (#1604)John McBridebefore adoption5b2b9e9

line 82why, one step back
82of the library.

Fixed linter issuesJuan Lenibefore adoption0ea93dd

line 83why, one step back
83

Removes viper dependency by removing cobra/ CLI tool (#1604)John McBridebefore adoption5b2b9e9

lines 84–86why, one step back
84```
85go get -u github.com/spf13/cobra@latest86```

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 87–93why, one step back
87
88Next, include Cobra in your application:8990```go91import "github.com/spf13/cobra"92```93

readme: split 'Getting Started' into 'user_guide.md'umarcorbefore adoptionace6b14

line 94why, one step back
94# Usage

Removes viper dependency by removing cobra/ CLI tool (#1604)John McBridebefore adoption5b2b9e9

lines 95–97why, one step back
95`cobra-cli` is a command line program to generate cobra applications and command files.
96It will bootstrap your application scaffolding to rapidly97develop a Cobra-based application. It is the easiest way to incorporate Cobra into your application.

Fixed linter issuesJuan Lenibefore adoption0ea93dd

line 98why, one step back
98

Removes viper dependency by removing cobra/ CLI tool (#1604)John McBridebefore adoption5b2b9e9

lines 99–104why, one step back
99It can be installed by running:
100101```102go install github.com/spf13/cobra-cli@latest103```104

Changed branch name in the cobra generator link to 'main' (#1645)Neville Bokdawallabefore adoptiond622355

line 105why, one step back
105For complete details on using the Cobra-CLI generator, please read [The Cobra Generator README](https://github.com/spf13/cobra-cli/blob/main/README.md)

Updating generator documentation and linksSteve Franciabefore adoptioncf87fc4

lines 106–107why, one step back
106
107For complete details on using the Cobra library, please read the [The Cobra User Guide](user_guide.md).

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 108–111why, one step back
108
109# License110111Cobra is released under the Apache 2.0 license. See [LICENSE.txt](https://github.com/spf13/cobra/blob/master/LICENSE.txt)