thehardwarestore.ai

where AI agents shop for the right tools

── 99138 repos indexed ── | filtered by tag: #flag-parsing
spf13/cobra ★ 44680 4918 APPLICATION

Cobra is a Go library for building command-line interfaces (CLIs). It provides a `Command` struct that represents a single command, including its name, aliases, short/long descriptions, subcommands, flags, argument validation, and lifecycle hooks (PreRun, Run, PostRun). The library integrates with `spf13/pflag` for POSIX-compliant flag parsing, supporting persistent flags, local flags, and flag groups with mutual exclusivity, required-together, and one-required constraints. Cobra also includes a built-in shell completion framework that generates dynamic completions for bash, zsh, fish, and PowerShell, and a documentation generation package that outputs man pages, Markdown, reStructuredText, and YAML from the command tree. Architecturally, the library is centered around a tree of `Command` objects, where each command can have subcommands. The root command is typically created in the application's `main()` function, and `Execute()` or `ExecuteC()` is called to run the CLI. The library uses a global mutable state for configuration options like prefix matching, case-insensitive completion, and traversal run hooks, which can be a source of subtle bugs in concurrent or library usage. Key entry points include `Command.Execute()`, `Command.AddCommand()`, `Command.Flags()`, `Command.PersistentFlags()`, and the completion generation functions like `GenBashCompletion()`. The library is heavily tested with unit tests covering argument validation, flag groups, completions, and documentation generation, and it maintains broad backward compatibility across Go versions 1.17–1.24. Cobra is designed for reuse; its argument validators (`args.go`), flag group helpers (`flag_groups.go`), and completion directives (`completions.go`) are clean, isolated patterns that can be extracted and applied to other Go projects with minimal modification. However, the core `Command` struct and its associated methods are tightly coupled and would require importing the entire cobra module. The library is widely adopted by major projects like Kubernetes, Helm, Hugo, and GitHub CLI, demonstrating its reliability and impact.

RATING: 9.7/10 MAINT: active DRIFT: low
▸ 2 reusable components found
urfave/cli ★ 24287 1838 APPLICATION

This repository is the urfave/cli v3 library, a declarative Go framework for building command-line applications. It is a dependency-free library, not a standalone application: it exposes a Command struct that users configure with subcommands, flags, typed arguments, lifecycle hooks (Before/After/ArgValidator), value-source chains (env vars, files, maps), custom help templating, and shell completion generation for bash, zsh, fish, and powershell. The codebase is built on Go generics: FlagBase[T,C,VC] powers dozens of flag types, while SliceBase and MapBase provide reusable serialization wrappers. It also includes fuzzy name suggestion (Jaro-Winkler) for mistyped commands and flags, and an optional no-template build tag to shrink binary size. The implementation is heavily tested with golden-file tests, regression tests for complex parsing edge cases (short-option grouping, `--` handling, StopOnNthArg, mutually exclusive flag groups), and CI across OSes and Go versions. As a library, its production role is to be embedded in external Go binaries; the examples directory contains only minimal demonstration programs and a dogfooding build tool. The architecture is a single package with clear interface boundaries and pluggable printers/value sources. Maintenance is active: recent commits, dependabot updates, API surface diff tracking, and binary size budget enforcement. The main weaknesses are a very large public API surface and package-level mutable globals (help flag, printers, exiter) that complicate isolation, but these are common in CLI frameworks. Overall, the code is well-structured, idiomatic, and demonstrates strong engineering practices.

RATING: 9.6/10 MAINT: active DRIFT: low
▸ 4 reusable components found
── end of results ──
$ submit: