Back to Skills

cli-patterns

verified

Lightweight Go CLI patterns using urfave/cli. Use when building CLI tools, creating commands with flags, implementing subcommands, adding before/after hooks, organizing command categories, or when user mentions Go CLI, urfave/cli, cobra alternatives, CLI flags, CLI categories.

View on GitHub

Marketplace

cli-builder

vanman2024/cli-builder

Plugin

cli-builder

development

Repository

vanman2024/cli-builder

plugins/cli-builder/skills/cli-patterns/SKILL.md

Last Verified

January 22, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/vanman2024/cli-builder/blob/main/plugins/cli-builder/skills/cli-patterns/SKILL.md -a claude-code --skill cli-patterns

Installation paths:

Claude
.claude/skills/cli-patterns/
Powered by add-skill CLI

Instructions

# CLI Patterns Skill

Lightweight Go CLI patterns using urfave/cli for fast, simple command-line applications.

## Overview

Provides battle-tested patterns for building production-ready CLI tools in Go using urfave/cli v2. Focus on simplicity, speed, and maintainability over complex frameworks like Cobra.

## Why urfave/cli?

- **Lightweight**: Minimal dependencies, small binary size
- **Fast**: Quick compilation, fast execution
- **Simple API**: Easy to learn, less boilerplate than Cobra
- **Production-ready**: Used by Docker, Nomad, and many other tools
- **Native Go**: Feels like standard library code

## Core Patterns

### 1. Basic CLI Structure

Use `templates/basic-cli.go` for simple single-command CLIs:
- Main command with flags
- Help text generation
- Error handling
- Exit codes

### 2. Subcommands

Use `templates/subcommands-cli.go` for multi-command CLIs:
- Command hierarchy (app → command → subcommand)
- Shared flags across commands
- Command aliases
- Command categories

### 3. Flags and Options

Use `templates/flags-demo.go` for comprehensive flag examples:
- String, int, bool, duration flags
- Required vs optional flags
- Default values
- Environment variable fallbacks
- Flag aliases (short and long forms)
- Custom flag types

### 4. Command Categories

Use `templates/categories-cli.go` for organized command groups:
- Group related commands
- Better help text organization
- Professional CLI UX
- Examples: database commands, deploy commands, etc.

### 5. Before/After Hooks

Use `templates/hooks-cli.go` for lifecycle management:
- Global setup (before all commands)
- Global cleanup (after all commands)
- Per-command setup/teardown
- Initialization and validation
- Resource management

### 6. Context and State

Use `templates/context-cli.go` for shared state:
- Pass configuration between commands
- Share database connections
- Manage API clients
- Context values

## Scripts

### Generation Scripts

**`scripts/generate-basic.sh <app-name>`**
- Generates 

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
7894 chars