Forge
1.x
Docs/Forge/CLI Framework
Open

Reading7 min
Updated31 Jul 2026
Sourcev1/cli/index.mdx

Forge CLI Framework is an enterprise-grade CLI framework for building powerful command-line tools in Go. It provides a comprehensive foundation for creating interactive, user-friendly CLI applications with modern UX patterns, extensive customization options, and seamless integration with Forge applications.

Note

The CLI framework is production-ready and actively maintained. It's designed to work both standalone and integrated with Forge applications for accessing services via dependency injection.

Key Features01

Architecture Overview02

The CLI framework follows a modular architecture with clear separation of concerns:

Key Features03

  • Commands & Subcommands - Hierarchical command structure

  • Comprehensive Flags - String, int, bool, slice, duration with validation

  • Interactive Prompts - Input, confirm, select, multi-select with arrow key navigation

  • Space Bar Selection - Toggle multi-select with spacebar (modern UX)

  • Progress Indicators - Progress bars and spinners

  • Table Output - Formatted, colored tables with multiple styles

  • Middleware - Before/after command hooks

  • Plugin System - Modular, composable commands

  • CLI-Optimized Logger - Color-coded, simple output

  • Auto-Generated Help - Automatic help text generation

  • Shell Completion - Bash, Zsh, Fish completion

  • Forge Integration - Access to DI container and services

Quick Start04

Get started with the CLI framework in minutes:

Tip

Make sure you have Go 1.21+ installed. The CLI framework works both standalone and integrated with Forge applications.

bash
# Create a new Go module
mkdir my-cli-tool && cd my-cli-tool
go mod init my-cli-tool

# Add CLI framework dependency
go get github.com/xraph/forge/cli

Interactive Example05

The CLI framework excels at creating interactive command-line experiences:

setupCmd := cli.NewCommand(
    "setup",
    "Interactive setup wizard",
    func(ctx cli.CommandContext) error {
        ctx.Info("Welcome to the setup wizard!")

        // Simple prompt
        name, err := ctx.Prompt("What's your name?")
        if err != nil {
            return err
        }

        // Confirm prompt
        confirmed, err := ctx.Confirm(fmt.Sprintf("Is '%s' correct?", name))
        if err != nil {
            return err
        }

        if !confirmed {
            ctx.Warning("Setup cancelled")
            return nil
        }

        // Select with arrow keys
        env, err := ctx.Select("Choose environment:", []string{
            "development",
            "staging", 
            "production",
        })
        if err != nil {
            return err
        }

        // Multi-select with spacebar
        features, err := ctx.MultiSelect("Select features:", []string{
            "database",
            "cache",
            "events",
            "streaming",
        })
        if err != nil {
            return err
        }

        // Progress bar for setup
        progress := ctx.ProgressBar(100)
        for i := 0; i <= 100; i += 10 {
            progress.Set(i)
            time.Sleep(100 * time.Millisecond)
        }
        progress.Finish("Setup complete!")

        ctx.Success("Configuration saved!")
        return nil
    },
)

Next Steps06

Community & Support07

  • GitHub: xraph/forge - Source code and issues

  • Examples: Check the /cli/examples directory for real-world examples

  • Documentation: Comprehensive guides and API reference

  • Contributing: We welcome contributions and feedback


Ready to build powerful CLI tools? Let's start with commands!