Skip to content
Myr

README.md

This file

Path

README.md

133 lines · 4.8 KiB · Markdown

Last changed by

Update README.md with new logoSteve Franciabefore adoption3f3b818

History of this file

Take it

The walk stopped after 200 commits: lines older than 89d7b83 point at it.

Update README.md with new logoSteve Franciabefore adoption3f3b818

lines 1–5why, one step back
1<div align="center">
2<a href="https://cobra.dev">3<img width="512" height="535" alt="cobra-logo" src="https://github.com/user-attachments/assets/c8bf9aad-b5ae-41d3-8899-d83baec10af8" />4</a>5</div>

New logoSteve Franciabefore adoption680936a

line 6why, one step back
6

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

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

Update README.md with new logoSteve Franciabefore adoption3f3b818

lines 8–10why, one step back
8
9<a href="https://cobra.dev">Visit Cobra.dev for extensive documentation</a> 10

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

line 11why, one step back
11

Change links from http:// to https:// (#1695)Andreas Deiningerbefore adoptionffa8860

line 12why, one step back
12Cobra is used in many Go projects such as [Kubernetes](https://kubernetes.io/),

Spelling for GitHub CLI (#1744)Ikko Ashiminebefore adoptiona0aadc6

line 13why, one step back
13[Hugo](https://gohugo.io), and [GitHub CLI](https://github.com/cli/cli) to

Move documentation sources to site/content (#1428)Unai Martinez-Corralbefore adoptiondcb405a

line 14why, one step back
14name a few. [This list](site/content/projects_using_cobra.md) contains a more extensive list of projects using Cobra.

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

line 15why, one step back
15

Update badge route (#1884)Seonghyeon Chobefore adoptionfdffa5a

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

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

lines 17–19why, one step back
17[![Go Reference](https://pkg.go.dev/badge/github.com/spf13/cobra.svg)](https://pkg.go.dev/github.com/spf13/cobra)
18[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/cobra)](https://goreportcard.com/report/github.com/spf13/cobra)19[![Slack](https://img.shields.io/badge/Slack-cobra-brightgreen)](https://gophers.slack.com/archives/CD3LP1199)

Adding sponsorship to README.mdSteve Franciabefore adoptiondb3ddb5

lines 20–33why, one step back
20<hr>
21<div align="center" markdown="1">22 <sup>Supported by:</sup>23 <br>24 <br>25 <a href="https://www.warp.dev/cobra">26 <img alt="Warp sponsorship" width="400" src="https://github.com/user-attachments/assets/ab8dd143-b0fd-4904-bdc5-dd7ecac94eae">27 </a>2829### [Warp, the AI terminal for devs](https://www.warp.dev/cobra)30[Try Cobra in Warp today](https://www.warp.dev/cobra)<br>3132</div>33<hr>

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

lines 34–46why, one step back
34
35# Overview3637Cobra is a library providing a simple interface to create powerful modern CLI38interfaces similar to git & go tools.3940Cobra provides:41* Easy subcommand-based CLIs: `app server`, `app fetch`, etc.42* Fully POSIX-compliant flags (including short & long versions)43* Nested subcommands44* Global, local and cascading flags45* Intelligent suggestions (`app srver`... did you mean `app server`?)46* Automatic help generation for commands and flags

Add groups for commands in help (#1003)aawsomebefore adoption2169adb

line 47why, one step back
47* Grouping help for subcommands

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

lines 48–52why, one step back
48* Automatic help flag recognition of `-h`, `--help`, etc.
49* Automatically generated shell autocomplete for your application (bash, zsh, fish, powershell)50* Automatically generated man pages for your application51* Command aliases so you can change things without breaking them52* The flexibility to define your own help, usage, etc.

Change links from http:// to https:// (#1695)Andreas Deiningerbefore adoptionffa8860

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

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

lines 54–64why, one step back
54
55# Concepts5657Cobra is built on a structure of commands, arguments & flags.5859**Commands** represent actions, **Args** are things and **Flags** are modifiers for those actions.6061The best applications read like sentences when used, and as a result, users62intuitively know how to interact with them.6364The pattern to follow is

Adjustments to documentation (#1656)Marc Khouzambefore adoption7e289f4

line 65why, one step back
65`APPNAME VERB NOUN --ADJECTIVE`

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

line 66why, one step back
66 or

Adjustments to documentation (#1656)Marc Khouzambefore adoption7e289f4

line 67why, one step back
67`APPNAME COMMAND ARG --FLAG`.

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

lines 68–103why, one step back
68
69A few good real world examples may better illustrate this point.7071In the following example, 'server' is a command, and 'port' is a flag:7273 hugo server --port=13137475In this command we are telling Git to clone the url bare.7677 git clone URL --bare7879## Commands8081Command is the central point of the application. Each interaction that82the application supports will be contained in a Command. A command can83have children commands and optionally run an action.8485In the example above, 'server' is the command.8687[More about cobra.Command](https://pkg.go.dev/github.com/spf13/cobra#Command)8889## Flags9091A flag is a way to modify the behavior of a command. Cobra supports92fully POSIX-compliant flags as well as the Go [flag package](https://golang.org/pkg/flag/).93A Cobra command can define flags that persist through to children commands94and flags that are only available to that command.9596In the example above, 'port' is the flag.9798Flag functionality is provided by the [pflag99library](https://github.com/spf13/pflag), a fork of the flag standard library100which maintains the same interface while adding POSIX compliance.101102# Installing103Using Cobra is easy. First, use `go get` to install the latest version

Move documentation sources to site/content (#1428)Unai Martinez-Corralbefore adoptiondcb405a

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

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

lines 105–128why, one step back
105
106```107go get -u github.com/spf13/cobra@latest108```109110Next, include Cobra in your application:111112```go113import "github.com/spf13/cobra"114```115116# Usage117`cobra-cli` is a command line program to generate cobra applications and command files.118It will bootstrap your application scaffolding to rapidly119develop a Cobra-based application. It is the easiest way to incorporate Cobra into your application.120121It can be installed by running:122123```124go install github.com/spf13/cobra-cli@latest125```126127For complete details on using the Cobra-CLI generator, please read [The Cobra Generator README](https://github.com/spf13/cobra-cli/blob/main/README.md)128

docs: update README.md (#2197)Ikko Eltociear Ashiminebefore adoption11ab621

line 129why, one step back
129For complete details on using the Cobra library, please read [The Cobra User Guide](site/content/user_guide.md).

Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83

lines 130–132why, one step back
130
131# License132

Move documentation sources to site/content (#1428)Unai Martinez-Corralbefore adoptiondcb405a

line 133why, one step back
133Cobra is released under the Apache 2.0 license. See [LICENSE.txt](LICENSE.txt)