Youssef Ameachaq's Blog

0. Who am I?

2. Introduction: Why Build a CLI?

2. Design Principles for a Great CLI

3. Getting Started with Go and Cobra

Setting Up the CLI

  1. Initialize the project:
    mkdir my-cli && cd my-cli
    go mod init github.com/username/my-cli
    go get -u github.com/spf13/cobra
  2. Create the project structure :
    /my-cli
       /cmd
           /name          # CLI commands
               main.go     # CLI entry point
       /internal           # Reusable code

Building the Root Command

4. Adding Commands

5. Enhancing Functionality

Reusable Components

Advanced CLI Features

6. Testing and Improving

7. Packaging and Releasing

Automate Builds with GoReleaser

GoReleaser automates the process of building, packaging, and releasing your CLI across platforms.

  1. Install GoReleaser:
    brew install goreleaser
  2. Create a .goreleaser.yaml file:
    cd cmd/drive-cli
    goreleaser init  
    goreleaser release --snapshot --clean 

Automate Releases with GitHub Actions

8. Closing Thoughts