![cobra logo](assets/CobraMain.png)
Cobra is a library for creating powerful modern CLI applications.
Cobra is used in many Go projects such as [Kubernetes](https://kubernetes.io/),
[Hugo](https://gohugo.io), and [GitHub CLI](https://github.com/cli/cli) to
name a few. [This list](site/content/projects_using_cobra.md) contains a more extensive list of projects using Cobra.
[![](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)
[![Go Reference](https://pkg.go.dev/badge/github.com/spf13/cobra.svg)](https://pkg.go.dev/github.com/spf13/cobra)
[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/cobra)](https://goreportcard.com/report/github.com/spf13/cobra)
[![Slack](https://img.shields.io/badge/Slack-cobra-brightgreen)](https://gophers.slack.com/archives/CD3LP1199)
# Overview
Cobra is a library providing a simple interface to create powerful modern CLI
interfaces similar to git & go tools.
Cobra 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
* Intelligent suggestions (`app srver`... did you mean `app server`?)
* Automatic help generation for commands and flags
* Grouping help for subcommands
* Automatic help flag recognition of `-h`, `--help`, etc.
* Automatically generated shell autocomplete for your application (bash, zsh, fish, powershell)
* 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 seamless integration with [viper](https://github.com/spf13/viper) for 12-factor apps
# Concepts
Cobra is built on a structure of commands, arguments & flags.
**Commands** represent actions, **Args** are things and **Flags** are modifiers for those actions.
The best applications read like sentences when used, and as a result, users
intuitively know how to interact with them.
The pattern to follow is
`APPNAME VERB NOUN --ADJECTIVE`
or
`APPNAME COMMAND ARG --FLAG`.
A few good real world examples may better illustrate this point.
In the following example, 'server' is a command, and 'port' is a flag:
hugo server --port=1313
In this command we are telling Git to clone the url bare.
git clone URL --bare
## Commands
Command is the central point of the application. Each interaction that
the application supports will be contained in a Command. A command can
have children commands and optionally run an action.
In the example above, 'server' is the command.
[More about cobra.Command](https://pkg.go.dev/github.com/spf13/cobra#Command)
## Flags
A flag is a way to modify the behavior of a command. Cobra supports
fully POSIX-compliant flags as well as the Go [flag package](https://golang.org/pkg/flag/).
A Cobra command can define flags that persist through to children commands
and flags that are only available to that command.
In the example above, 'port' is the flag.
Flag functionality is provided by the [pflag
library](https://github.com/spf13/pflag), a fork of the flag standard library
which maintains the same interface while adding POSIX compliance.
# Installing
Using Cobra is easy. First, use `go get` to install the latest version
of the library.
```
go get -u github.com/spf13/cobra@latest
```
Next, include Cobra in your application:
```go
import "github.com/spf13/cobra"
```
# Usage
`cobra-cli` is a command line program to generate cobra applications and command files.
It will bootstrap your application scaffolding to rapidly
develop a Cobra-based application. It is the easiest way to incorporate Cobra into your application.
It can be installed by running:
```
go install github.com/spf13/cobra-cli@latest
```
For complete details on using the Cobra-CLI generator, please read [The Cobra Generator README](https://github.com/spf13/cobra-cli/blob/main/README.md)
For complete details on using the Cobra library, please read [The Cobra User Guide](site/content/user_guide.md).
# License
Cobra is released under the Apache 2.0 license. See [LICENSE.txt](LICENSE.txt)
没有合适的资源?快使用搜索试试~ 我知道了~
用于现代 Go CLI 交互的 Commander.zip
共68个文件
go:36个
md:16个
yml:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2024-12-03
04:41:08
上传
评论
收藏 221KB ZIP 举报
温馨提示
Cobra 是一个用于创建强大的现代 CLI 应用程序的库。Cobra 在许多 Go 项目中使用,例如Kubernetes、 Hugo和GitHub CLI等等。此列表包含使用 Cobra 的更多项目列表。 概述Cobra 是一个提供简单接口的库,用于创建类似于 git 和 go 工具的强大的现代 CLI 接口。Cobra 提供简单的基于子命令的 CLIapp server、、app fetch等等。完全符合 POSIX 标准的标志(包括短版本和长版本)嵌套子命令全局、本地和级联标志智能建议(app srver...您的意思是app server?)自动生成命令和标志的帮助子命令的分组帮助自动帮助标志识别-h、--help等。为您的应用程序自动生成 shell 自动完成功能(bash、zsh、fish、powershell)为您的应用程序自动生成手册页命令别名,这样你就可以更改内容而不会破坏它们灵活地定义您自己的帮助、用法等。可选与viper无缝集成,适用于 12 要素应用概念Cobra 建立在命令、参数和标志的结构之上。命
资源推荐
资源详情
资源评论
收起资源包目录
用于现代 Go CLI 交互的 Commander.zip (68个子文件)
zsh_completions_test.go 995B
args_test.go 15KB
zsh_completions.go 11KB
.mailmap 172B
site
content
projects_using_cobra.md 3KB
active_help.md 8KB
docgen
yaml.md 3KB
man.md 519B
rest.md 3KB
md.md 3KB
_index.md 445B
completions
powershell.md 147B
zsh.md 4KB
fish.md 116B
bash.md 4KB
_index.md 26KB
user_guide.md 24KB
go.mod 194B
.github
dependabot.yml 241B
labeler.yml 597B
workflows
test.yml 2KB
labeler.yml 387B
size-labeler.yml 962B
标签.txt 41B
go.sum 1KB
assets
CobraMain.png 72KB
active_help.go 3KB
doc
md_docs_test.go 4KB
rest_docs_test.go 3KB
rest_docs.go 5KB
util.go 2KB
yaml_docs.go 5KB
cmd_test.go 3KB
md_docs.go 5KB
man_examples_test.go 1KB
yaml_docs_test.go 3KB
man_docs.go 7KB
man_docs_test.go 7KB
LICENSE.txt 10KB
Makefile 907B
powershell_completions.go 13KB
args.go 4KB
CONTRIBUTING.md 2KB
command_notwin.go 689B
shell_completions.go 4KB
MAINTAINERS 137B
fish_completions.go 11KB
bash_completionsV2.go 13KB
bash_completions.go 22KB
cobra_test.go 5KB
flag_groups.go 9KB
flag_groups_test.go 9KB
资源内容.txt 1KB
fish_completions_test.go 4KB
completions.go 35KB
cobra.go 7KB
active_help_test.go 12KB
bash_completions_test.go 10KB
.golangci.yml 1KB
.gitignore 484B
command_win.go 1KB
completions_test.go 103KB
CONDUCT.md 3KB
command_test.go 75KB
README.md 4KB
bash_completionsV2_test.go 1007B
command.go 55KB
powershell_completions_test.go 1000B
共 68 条
- 1
资源评论
赵闪闪168
- 粉丝: 1677
- 资源: 5392
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 船查找器67-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- <项目代码>YOLOv8 航拍路面病害识别<目标检测>
- 在线考试系统,springboot+vue前面分离了一个项目,记录自己毕业设计完成的情况.zip
- 用于引力波探测的低噪声激光器
- C语言标准I/O库中的文件读写操作详解及应用实例
- 计算机网络期末复习全面指南:基本概念、体系架构及技术解析
- 基于无监督学习,无需训练,先使用SIFT算法提取图像特征,再使用KMeans聚类算法进行图像分类+源码+文档说明(高分作品)
- 241204 英语语法-五种句型.md
- 商城系统前分离SpringBoot+Vue 【毕业设计系统】.zip
- 鸿蒙next项目demo
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功