# spf13/cobra

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/spf13-cobra).**

43,265 stars · 3,056 forks · Go · apache-2.0

## Links

- GitHub: https://github.com/spf13/cobra
- Homepage: https://cobra.dev
- awesome-repositories: https://awesome-repositories.com/repository/spf13-cobra.md

## Topics

`cli` `cli-app` `cobra` `cobra-generator` `cobra-library` `command` `command-cobra` `command-line` `commandline` `go` `golang` `golang-application` `golang-library` `posix` `posix-compliant-flags` `subcommands`

## Description

Cobra is a development framework for building command-line applications in Go. It organizes application logic into a hierarchical tree structure where each node represents a command, complete with its own flags and execution logic. This structure allows developers to build complex, nested command interfaces that mirror business domains while maintaining a clean separation between command orchestration and underlying business logic.

The framework distinguishes itself through its declarative approach to metadata and configuration. It automatically derives help documentation, usage instructions, and shell completion scripts directly from the defined command and flag structures. Furthermore, it provides a robust configuration management layer that merges settings from default values, configuration files, environment variables, and command-line flags based on defined precedence rules, ensuring consistent behavior across different environments.

Beyond core command and configuration management, the project includes a middleware hook system for injecting cross-cutting concerns like authentication, telemetry, or validation into the command execution lifecycle. It also supports advanced interface patterns such as persistent flag propagation, command aliasing, and a plugin architecture for extending functionality without recompilation. The framework includes built-in utilities for project scaffolding, programmatic command testing, and error propagation to support the development of professional-grade terminal tools.

## Tags

### Development Tools & Productivity

- [CLI Frameworks](https://awesome-repositories.com/f/development-tools-productivity/cli-frameworks.md) — Provides the core structure for building professional command-line tools with nested subcommands and flags.
- [Command Line Frameworks](https://awesome-repositories.com/f/development-tools-productivity/command-line-frameworks.md) — Organizes command-line applications into hierarchical trees of nested subcommands and flags.
- [Command Hierarchies](https://awesome-repositories.com/f/development-tools-productivity/command-hierarchies.md) — Organizes application logic into a nested tree structure where each node represents a command with its own flags and execution logic.
- [Flag Definitions](https://awesome-repositories.com/f/development-tools-productivity/flag-definitions.md) — Supports creating persistent and local flags with custom types, validation, mutual exclusivity, and hidden options. ([source](https://cobra.dev/docs/explanations/enterprise-guide/))
- [Configuration Management](https://awesome-repositories.com/f/development-tools-productivity/configuration-management.md) — Merges settings from defaults, files, environment variables, and flags using defined precedence rules.
- [Configuration Managers](https://awesome-repositories.com/f/development-tools-productivity/configuration-managers.md) — Orchestrates settings across multiple sources using a unified hierarchy and precedence rules.
- [Subcommand Registration](https://awesome-repositories.com/f/development-tools-productivity/subcommand-registration.md) — Allows attaching child commands to a parent structure during initialization to build complex, hierarchical command interfaces. ([source](https://cobra.dev/docs/how-to-guides/working-with-commands/))
- [Command Orchestration](https://awesome-repositories.com/f/development-tools-productivity/command-orchestration.md) — Organizes applications into nested command trees that mirror business domains for clean separation of concerns. ([source](https://cobra.dev/docs/explanations/enterprise-guide/))
- [Configuration Layers](https://awesome-repositories.com/f/development-tools-productivity/configuration-layers.md) — Resolves application settings by merging multiple sources into a unified hierarchy.
- [Configuration Resolution](https://awesome-repositories.com/f/development-tools-productivity/configuration-resolution.md) — Loads settings from files, environment variables, and defaults using hierarchical resolution to ensure consistent behavior. ([source](https://cobra.dev/docs/examples/02-task-manager/))
- [Configuration Resolvers](https://awesome-repositories.com/f/development-tools-productivity/configuration-resolvers.md) — Centralizes configuration management to ensure consistent value resolution across different input sources. ([source](https://cobra.dev/docs/learning-resources/learning-journey/))
- [Execution Middleware](https://awesome-repositories.com/f/development-tools-productivity/execution-middleware.md) — Implements cross-cutting concerns like authentication and telemetry through reusable command hooks.
- [Middleware Systems](https://awesome-repositories.com/f/development-tools-productivity/middleware-systems.md) — Provides a hook system to execute cross-cutting logic at pre-run and post-run stages. ([source](https://cobra.dev/docs/explanations/enterprise-guide/))
- [Documentation Generators](https://awesome-repositories.com/f/development-tools-productivity/documentation-generators.md) — Creates synchronized help text and markdown documentation directly from command definitions.
- [Flag Propagation](https://awesome-repositories.com/f/development-tools-productivity/flag-propagation.md) — Allows parent-level configuration flags to be inherited by all descendant subcommands for consistent global settings.
- [Help Generators](https://awesome-repositories.com/f/development-tools-productivity/help-generators.md) — Generates synchronized help documentation directly from command structures with support for custom formatting. ([source](https://cobra.dev/docs/explanations/enterprise-guide/))
- [Plugin Systems](https://awesome-repositories.com/f/development-tools-productivity/plugin-systems.md) — Supports extending application functionality without recompilation by discovering and integrating external binaries. ([source](https://cobra.dev/docs/explanations/enterprise-guide/))
- [Shell Environment Integrations](https://awesome-repositories.com/f/development-tools-productivity/shell-environment-integrations.md) — Handles standard input and output piping, exit codes, and environment variable binding. ([source](https://cobra.dev/docs/examples/03-api-inspector/))
- [Execution Hooks](https://awesome-repositories.com/f/development-tools-productivity/execution-hooks.md) — Provides pre-run and post-run extension points for injecting cross-cutting concerns like authentication or telemetry.
- [Flag Validation](https://awesome-repositories.com/f/development-tools-productivity/flag-validation.md) — Supports custom validation checks for flag relationships or value constraints to ensure valid input before execution. ([source](https://cobra.dev/docs/how-to-guides/working-with-flags/))
- [Flag Validation Utilities](https://awesome-repositories.com/f/development-tools-productivity/flag-validation-utilities.md) — Enforces mandatory flag requirements and provides automated error feedback for missing inputs. ([source](https://cobra.dev/docs/how-to-guides/working-with-flags/))
- [Modular Architecture](https://awesome-repositories.com/f/development-tools-productivity/modular-architecture.md) — Enables separating command logic into distinct packages with constructor functions to maintain clean dependencies. ([source](https://cobra.dev/docs/how-to-guides/working-with-commands/))
- [Shell Autocompletion Providers](https://awesome-repositories.com/f/development-tools-productivity/shell-autocompletion-providers.md) — Improves user productivity by providing dynamic, context-aware command and flag suggestions.
- [Shell Completion Generators](https://awesome-repositories.com/f/development-tools-productivity/shell-completion-generators.md) — Produces dynamic, context-aware auto-completion scripts for various terminal environments.
- [Shell Completion Integrations](https://awesome-repositories.com/f/development-tools-productivity/shell-completion-integrations.md) — Generates and installs completion scripts to enable command-line argument auto-completion. ([source](https://cobra.dev/docs/how-to-guides/shell-completion/))

### Testing & Quality Assurance

- [CLI Testing Frameworks](https://awesome-repositories.com/f/testing-quality-assurance/cli-testing-frameworks.md) — Verifies command logic in isolation or as complete flows using programmatic execution. ([source](https://cobra.dev/docs/explanations/enterprise-guide/))

### Software Engineering & Architecture

- [Error Propagation Systems](https://awesome-repositories.com/f/software-engineering-architecture/error-propagation-systems.md) — Enables predictable error propagation through command hierarchies without forced process termination. ([source](https://cobra.dev/docs/explanations/enterprise-guide/))
