CLI OUTPUT QUICK REFERENCE - nself-org/cli GitHub Wiki
One-page cheat sheet for common CLI output functions.
source "src/lib/utils/cli-output.sh"| Function | Usage | Output |
|---|---|---|
cli_success "msg" |
Success | โ msg (green) |
cli_error "msg" |
Error | โ msg (red, stderr) |
cli_warning "msg" |
Warning | โ msg (yellow, stderr) |
cli_info "msg" |
Info | โน msg (blue) |
cli_debug "msg" |
Debug | [DEBUG] msg (if DEBUG=true) |
| Function | Usage | Purpose |
|---|---|---|
cli_header "Title" |
Major section | Double-line box header |
cli_section "Name" |
Subsection | โ Name (bold) |
cli_step 1 5 "task" |
Multi-step | โ Step 1/5 โ task |
cli_box "message" [type]
# Types: info, success, error, warning
cli_box_detailed "Title" "Content"
# Longer content with word wrapcli_list_item "text" # โข text
cli_list_numbered 1 "text" # 1. text
cli_list_checked "text" # [โ] text
cli_list_unchecked "text" # [ ] textcli_table_header "Col1" "Col2" "Col3"
cli_table_row "A" "B" "C"
cli_table_row "D" "E" "F"
cli_table_footer "Col1" "Col2" "Col3"# Progress bar
cli_progress "Task" 50 100 # [โโโโโโโโโโโโโโโโโโ] 50%
# Spinner
pid=$(cli_spinner_start "Loading...")
# ... do work ...
cli_spinner_stop $pid "Done"cli_summary "Title" "Item1" "Item2" "Item3"
cli_banner "Title" "Subtitle"
cli_separator [width]cli_blank [count] # Blank lines
cli_center "text" width # Center text
cli_indent "text" level # Indent text
echo "text" | cli_strip_colors # Remove colors#!/usr/bin/env bash
source "src/lib/utils/cli-output.sh"
main() {
cli_header "Command Name"
cli_section "Phase 1"
cli_info "Starting..."
# ... work ...
cli_success "Phase 1 complete"
cli_summary "Complete" "Item 1" "Item 2"
}
main "$@"if ! command; then
cli_error "Operation failed"
cli_info "Try: nself help command"
exit 1
fi
cli_success "Operation succeeded"steps=5
cli_step 1 $steps "Step 1"
# ... work ...
cli_step 2 $steps "Step 2"
# ... work ...
cli_summary "Complete" "All steps done"cli_table_header "Service" "Status" "Port"
cli_table_row "postgres" "running" "5432"
cli_table_row "hasura" "running" "8080"
cli_table_footer "Service" "Status" "Port"NO_COLOR=1 # Disable colors
DEBUG=true # Show debug messagesCLI_RED CLI_GREEN CLI_YELLOW CLI_BLUE
CLI_BOLD CLI_DIM CLI_RESETCLI_ICON_SUCCESS CLI_ICON_ERROR CLI_ICON_WARNING
CLI_ICON_INFO CLI_ICON_ARROW CLI_ICON_BULLET-
Always use printf - Never
echo -e - stderr for errors/warnings - cli_error and cli_warning use stderr
- 60-char standard - Most functions use 60-character width
- TTY detection - Spinners auto-disable in non-interactive mode
- NO_COLOR - Always respect user's NO_COLOR setting
See CLI-OUTPUT-LIBRARY.md for complete API reference.
bash src/examples/cli-output-demo.sh # Interactive demo
bash src/tests/unit/test-cli-output-quick.sh # Quick test