cli package provides a complete toolkit for building professional command-line interfaces. It includes utilities for command management, terminal output, user prompts, and more.
Sub-packages
Commander
Enhanced Cobra command management with hooks, topics, and reference generation
Printer
Terminal output utilities including tables, spinners, and progress bars
Prompter
Interactive user input with selections and confirmations
Terminator
Terminal detection and browser/pager utilities
Releaser
GitHub release checking and version management utilities
Installation
Commander
Thecommander package extends Cobra with enhanced features for CLI management.
Manager
Creating a Manager
Manager Options
WithTopics
WithHooks
Manager Methods
Init
IsCommandErr
Printer
Theprinter package provides utilities for formatted terminal output.
Table
Spinner
Progress Bar
Structured Output
Support for JSON and YAML output formats.Prompter
Theprompter package provides interactive user input utilities.
Prompter Interface
Creating a Prompter
Select
MultiSelect
Input
Confirm
Complete CLI Example
Here’s a complete example combining all CLI utilities:Best Practices
Use Spinners for Long Operations
Use Spinners for Long Operations
Always provide visual feedback for operations that take more than a second:
Confirm Destructive Actions
Confirm Destructive Actions
Always confirm before performing destructive operations:
Support Multiple Output Formats
Support Multiple Output Formats
Allow users to choose between table, JSON, and YAML output:
Organize Commands with Topics
Organize Commands with Topics
Use help topics to provide additional documentation: