Skip to content

Quick Start

Get up and running with CLI Template in minutes.

Basic Usage

Hello Command

The template includes a sample hello command:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Basic greeting
cli-template hello
# Output: Hello, World!

# Custom greeting
cli-template hello --name "Developer"
# Output: Hello, Developer!

# Short flag
cli-template hello -n "Go"
# Output: Hello, Go!

Help and Version

1
2
3
4
5
6
# Show help
cli-template --help
cli-template hello --help

# Show version
cli-template --version

Customizing Your CLI

1. Modify the Root Command

Edit cmd/root.go to customize the main command:

1
2
3
4
5
6
var rootCmd = &cobra.Command{
    Use:   "your-app-name",
    Short: "Your app description",
    Long:  `Your detailed app description.`,
    // ... rest of configuration
}

2. Add New Commands

Create new command files in the cmd/ directory:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
// cmd/your-command.go
package cmd

import (
    "fmt"
    "github.com/spf13/cobra"
)

var yourCmd = &cobra.Command{
    Use:   "your-command",
    Short: "Description of your command",
    Run: func(cmd *cobra.Command, args []string) {
        fmt.Println("Your command executed!")
    },
}

func init() {
    rootCmd.AddCommand(yourCmd)
}

3. Update Module Name

Update the Go module name in go.mod:

1
2
3
module github.com/yourusername/your-app-name

go 1.21

And update all imports accordingly.

Building Your Application

Development Build

1
2
3
4
5
6
7
8
# Build for current platform
make build

# Run without building
make run

# Development mode with hot reload
make dev

Cross-Platform Build

1
2
3
4
5
# Create snapshot release (all platforms)
make release-snapshot

# Check built binaries
ls dist/

Production Release

1
2
3
4
5
# Tag a version
git tag v1.0.0
git push origin v1.0.0

# This triggers GitHub Actions to create a release

Testing

Run Tests

1
2
3
4
5
6
7
8
# Run all tests
make test

# Run tests with coverage
make test-coverage

# View coverage report
open coverage.html

Add New Tests

Create test files alongside your commands:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// cmd/your-command_test.go
package cmd

import (
    "testing"
)

func TestYourCommand(t *testing.T) {
    // Your test implementation
}

Next Steps