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 fileTake 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 back1<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 back6Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83
line 7why, one step back7Cobra is a library for creating powerful modern CLI applications.Update README.md with new logoSteve Franciabefore adoption3f3b818
lines 8–10why, one step back89<a href="https://cobra.dev">Visit Cobra.dev for extensive documentation</a> 10Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83
line 11why, one step back11Change links from http:// to https:// (#1695)Andreas Deiningerbefore adoptionffa8860
line 12why, one step back12Cobra is used in many Go projects such as [Kubernetes](https://kubernetes.io/),Spelling for GitHub CLI (#1744)Ikko Ashiminebefore adoptiona0aadc6
line 13why, one step back13[Hugo](https://gohugo.io), and [GitHub CLI](https://github.com/cli/cli) toMove documentation sources to site/content (#1428)Unai Martinez-Corralbefore adoptiondcb405a
line 14why, one step back14name 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 back15Update badge route (#1884)Seonghyeon Chobefore adoptionfdffa5a
line 16why, one step back16[](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 back17[](https://pkg.go.dev/github.com/spf13/cobra)18[](https://goreportcard.com/report/github.com/spf13/cobra)19[](https://gophers.slack.com/archives/CD3LP1199)Adding sponsorship to README.mdSteve Franciabefore adoptiondb3ddb5
lines 20–33why, one step back20<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 back3435# 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 flagsAdd groups for commands in help (#1003)aawsomebefore adoption2169adb
line 47why, one step back47* Grouping help for subcommandsAdd Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83
lines 48–52why, one step back48* 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 back53* Optional seamless integration with [viper](https://github.com/spf13/viper) for 12-factor appsAdd Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83
lines 54–64why, one step back5455# 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 isAdjustments to documentation (#1656)Marc Khouzambefore adoption7e289f4
line 65why, one step back65`APPNAME VERB NOUN --ADJECTIVE`Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83
line 66why, one step back66 orAdjustments to documentation (#1656)Marc Khouzambefore adoption7e289f4
line 67why, one step back67`APPNAME COMMAND ARG --FLAG`.Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83
lines 68–103why, one step back6869A 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 versionMove documentation sources to site/content (#1428)Unai Martinez-Corralbefore adoptiondcb405a
line 104why, one step back104of the library.Add Polygon Edge as a project using Cobra (#1672)Miloš Živkovićbefore adoption89d7b83
lines 105–128why, one step back105106```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)128docs: update README.md (#2197)Ikko Eltociear Ashiminebefore adoption11ab621
line 129why, one step back129For 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 back130131# License132Move documentation sources to site/content (#1428)Unai Martinez-Corralbefore adoptiondcb405a
line 133why, one step back133Cobra is released under the Apache 2.0 license. See [LICENSE.txt](LICENSE.txt)