Skip to content

CLI Tool - Complete Guide

The CLI tool (cli) is a comprehensive toolkit for managing CLI projects built with the go-zoox/cli framework. It provides commands for project initialization, management, code quality, and more.

Installation

bash
go install github.com/go-zoox/cli/cmd/cli@latest

Or build from source:

bash
go build -o cli ./cmd/cli

Commands Overview

The CLI tool provides the following commands:

Project Management

  • init - Initialize a new CLI project
  • add - Add commands or flags to existing project
  • remove - Remove commands or flags from project
  • list - List commands and flags in project
  • update - Update command or flag properties
  • validate - Validate project structure

Templates

Code Quality

  • format - Format code with gofmt/goimports
  • lint - Lint code with golangci-lint/go vet
  • test - Generate test files

Project Enhancement

  • upgrade - Upgrade CLI framework version
  • migrate - Migrate project structure
  • config - Manage CLI tool configuration

Development Tools

  • build - Build CLI project
  • run - Run CLI project
  • watch - Watch for file changes

Documentation

  • docs - Generate documentation
  • man - Generate man page
  • completion - Generate shell completion scripts

Utilities


init

Initialize a new CLI project.

Usage

bash
cli init [options]

Options

FlagShortDescriptionDefault
--name-nProject nameRequired
--type-tCLI type (single|multiple)single
--output-oOutput directory.
--skip-interactive-sSkip interactive promptsfalse

Examples

bash
# Interactive mode
cli init

# Mixed mode
cli init --name myapp --type multiple

# Non-interactive mode
cli init --name myapp --type single --output ./myapp --skip-interactive

Generated Examples

The init command automatically generates example code to help you get started:

Single Command Mode includes:

  • --name flag (string, default: "World", alias: -n)
  • --verbose flag (bool, alias: -v)

Multiple Commands Mode includes:

  • list command with --all flag (bool, alias: -a)
  • create command with --name flag (string, required, alias: -n)

You can modify these examples or use cli add to add more commands and flags.

See Also


add

Add a command or flag to an existing CLI project.

Usage

bash
cli add [options]

Options

FlagShortDescription
--command-cCommand name to add
--flag-fFlag name to add
--to-commandAdd flag to specific command
--dir-dProject directory

Examples

bash
# Add a command
cli add --command delete

# Add a flag
cli add --flag verbose

# Add flag to specific command
cli add --flag limit --to-command list

remove

Remove a command or flag from an existing CLI project.

Usage

bash
cli remove [options]

Options

FlagShortDescription
--command-cCommand name to remove
--flag-fFlag name to remove
--from-commandRemove flag from specific command
--dir-dProject directory
--forceSkip confirmation

Examples

bash
# Remove a command
cli remove --command delete

# Remove a flag
cli remove --flag verbose

# Remove flag from specific command
cli remove --flag limit --from-command list

list

List commands and flags in an existing CLI project.

Usage

bash
cli list [options]

Options

FlagShortDescriptionDefault
--dir-dProject directory.
--format-fOutput format (table|json|yaml)table

Examples

bash
# List all commands and flags
cli list

# List in JSON format
cli list --format json

# List in YAML format
cli list --format yaml

update

Update command or flag properties in an existing CLI project.

Usage

bash
cli update [options]

Options

FlagShortDescription
--command-cCommand name to update
--flag-fFlag name to update
--usageNew usage/description for command
--flag-usageNew usage for flag
--flag-defaultNew default value for flag
--from-commandUpdate flag in specific command
--dir-dProject directory

Examples

bash
# Update command usage
cli update --command list --usage "List all items"

# Update flag default value
cli update --flag port --flag-default 3000

# Update flag in specific command
cli update --flag limit --from-command list --flag-default 10

validate

Validate an existing CLI project structure and code.

Usage

bash
cli validate [options]

Options

FlagShortDescriptionDefault
--dir-dProject directory.
--fixAttempt to fix issues (gofmt)false
--format-fOutput format (text|json)text

Examples

bash
# Validate project
cli validate

# Validate and fix issues
cli validate --fix

# Validate with JSON output
cli validate --format json

template

Manage CLI project templates.

Usage

bash
cli template <subcommand> [options]

Subcommands

list

List all available templates.

bash
cli template list

add

Add a new template.

bash
cli template add --name <name> --path <path> [--type <type>]

Options:

  • --name, -n: Template name (required)
  • --path, -p: Template path (required)
  • --type, -t: Template type (local|github|gitlab) (default: local)

Examples:

bash
# Add local template
cli template add --name my-template --path ./templates/my-template

# Add GitHub template
cli template add --name github-template --path github:user/repo --type github

remove

Remove a template.

bash
cli template remove --name <name>

Options:

  • --name, -n: Template name to remove (required)

use

Use a template to initialize a project.

bash
cli template use --name <name> [--output <dir>]

Options:

  • --name, -n: Template name to use (required)
  • --output, -o: Output directory (default: .)

Examples:

bash
# Use built-in template
cli template use --name api-client --output ./my-api-client

# Use custom template
cli template use --name my-template --output ./my-project

Built-in Templates

  • basic - Basic CLI template (default)
  • api-client - API client CLI template
  • file-manager - File management CLI template
  • server - Server management CLI template
  • database - Database CLI template
  • devops - DevOps CLI template

format

Format Go code using gofmt and goimports.

Usage

bash
cli format [options]

Options

FlagShortDescriptionDefault
--dir-dProject directory.
--check-cCheck if code is formatted (don't modify)false

Examples

bash
# Format code
cli format

# Check formatting
cli format --check

lint

Lint Go code using golangci-lint or go vet.

Usage

bash
cli lint [options]

Options

FlagShortDescriptionDefault
--dir-dProject directory.
--fix-fAutomatically fix issuesfalse

Examples

bash
# Lint code
cli lint

# Lint and fix issues
cli lint --fix

test

Generate test files for commands or flags.

Usage

bash
cli test [options]

Options

FlagShortDescription
--dir-dProject directory
--command-cGenerate test for specific command

Examples

bash
# Generate general test file
cli test

# Generate test for specific command
cli test --command list

upgrade

Upgrade CLI framework version.

Usage

bash
cli upgrade [options]

Options

FlagShortDescription
--dir-dProject directory
--to-tUpgrade to specific version
--check-cCheck for available upgrades

Examples

bash
# Check for upgrades
cli upgrade --check

# Upgrade to latest version
cli upgrade

# Upgrade to specific version
cli upgrade --to v1.2.0

migrate

Migrate project structure.

Usage

bash
cli migrate [options]

Options

FlagShortDescription
--dir-dProject directory
--to-tTarget structure (required)

Examples

bash
# Migrate single command to multiple commands
cli migrate --to multiple

config

Manage CLI tool configuration.

Usage

bash
cli config [options]

Options

FlagShortDescription
--key-kConfig key
--value-vConfig value (for set)

Examples

bash
# List all config
cli config

# Get config value
cli config --key output.format

# Set config value
cli config --key output.format --value json

build

Build CLI project.

Usage

bash
cli build [options]

Options

FlagShortDescription
--dir-dProject directory
--output-oOutput binary path
--platform-pTarget platform (e.g., linux/amd64)

Examples

bash
# Build for current platform
cli build

# Build for specific platform
cli build --platform linux/amd64

# Build with custom output
cli build --output ./bin/myapp

run

Run CLI project.

Usage

bash
cli run [options] [-- <args>]

Options

FlagShortDescription
--dir-dProject directory

Examples

bash
# Run project
cli run

# Run with arguments
cli run -- --help
cli run -- --name "World"

watch

Watch for file changes and rebuild.

Usage

bash
cli watch [options]

Options

FlagShortDescriptionDefault
--dir-dProject directory.
--build-bRebuild on changesfalse
--test-tRun tests on changesfalse

Examples

bash
# Watch and rebuild
cli watch --build

# Watch and run tests
cli watch --test

# Watch, rebuild and test
cli watch --build --test

docs

Generate documentation.

Usage

bash
cli docs [options]

Options

FlagShortDescriptionDefault
--dir-dProject directory.
--output-oOutput directory./docs
--format-fOutput formatmarkdown

Examples

bash
# Generate documentation
cli docs

# Generate to custom directory
cli docs --output ./documentation

man

Generate man page.

Usage

bash
cli man [options]

Options

FlagShortDescription
--dir-dProject directory

Examples

bash
# Generate man page
cli man

completion

Generate shell completion script.

Usage

bash
cli completion --shell <shell> [options]

Options

FlagShortDescription
--shell-sShell type (bash|zsh|fish|powershell) (required)
--dir-dProject directory

Examples

bash
# Generate bash completion
cli completion --shell bash

# Generate zsh completion
cli completion --shell zsh

# Install bash completion
cli completion --shell bash > /etc/bash_completion.d/cli

# Install zsh completion
cli completion --shell zsh > ~/.zsh/completions/_cli

version

Show version information.

Usage

bash
cli version

Examples

bash
cli version

Output:

cli tool version 0.1.0
CLI framework: github.com/go-zoox/cli

Tips and Best Practices

  1. Use Mixed Mode: Provide what you know via flags, let the tool ask for the rest
  2. Validate Before Committing: Run cli validate before committing changes
  3. Format Code: Use cli format to ensure consistent code style
  4. Use Templates: Leverage built-in templates for common project types
  5. Version Control: Always commit generated code to version control
  6. Test Generation: Use cli test to scaffold test files
  7. Documentation: Generate docs with cli docs for better project documentation

Troubleshooting

Command not found

Make sure you've installed the CLI tool:

bash
go install github.com/go-zoox/cli/cmd/cli@latest

Build errors

Run go mod tidy to ensure dependencies are resolved:

bash
go mod tidy

Template not found

Check available templates:

bash
cli template list

Validation errors

Use --fix flag to automatically fix some issues:

bash
cli validate --fix

See Also

Released under the MIT License.