Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build Your First CLI App With Golang

Build Your First CLI App With Golang

Go is a powerful choice for building fast, portable, and reliable tools — and it's especially great for improving developer experience. In this beginner-friendly talk, we'll walk through how to create your first custom dev tool using Go, and show how just a few lines of code can automate workflows, reduce friction, and save time for developers.

We’ll start with the basics of Go's CLI capabilities, including flag parsing, concurrency, directory scanning, and file I/O — then put it all together in a live demo where we build a simple, yet impactful CLI tool: a tool that check your Go project dependency health and alert you of vulnerabilities or upgrades available. The kind of tool your team would actually use.

You’ll leave this talk with:
- A clear understanding of how to build and structure Go CLI tools
- A live-coded example of a practical developer tool focused on real-world DX
- Tips for packaging and sharing your tool internally or as open source
- Motivation to build your own dev tools with Go, no matter your level of experience

No prior Go knowledge required — just curiosity and a passion for improving the developer workflow!

Avatar for Desmond Obisi

Desmond Obisi

October 27, 2025
Tweet

More Decks by Desmond Obisi

Other Decks in Programming

Transcript

  1. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Build Your ‘First’ { < From Idea to CLI in 30 Minutes > GopherCon Africa 2025 [Developer Tool With Go] } title.go about.go
  2. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 ‘Desmond Obisi’ OSS, Engineer, Writer { < I am a product engineer during the day, OSS maintainer, indie hacker and every other thing during the night. Love developer experience engineering, forced to do B2B SaaS by capitalism > GopherCon Africa 2025 title.go about.go }
  3. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 01 < How to build professional command-line tools that developers actually want to use > What You’ll Learn 02 < A tool that checks if your project's dependencies are healthy, secure, and up-to-date > What we are Building 03 < 94% of applications use open source dependencies, but only 35% regularly check them for issues> Why It Matters Objectives of ‘This Talk’ { } GopherCon Africa 2025 about.go objectives.go
  4. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 The Problems ‘Developer Faces’; GopherCon Africa 2025 objectives.go problems.go 😰 Current Reality: • You inherit a project with 50+ dependencies • Some haven't been updated in 2 years • You have no idea if they have security issues • Checking each one manually takes hours ✨ Our Solution: • One command tells you everything • Checks all dependencies in parallel (seconds!) • Shows security vulnerabilities instantly • Gives you a health score to track progress Real Impact: The Equifax breach (143 million people affected) happened because of an outdated dependency that had a known fix available for months.
  5. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Why Golang? ‘Reason’: GopherCon Africa 2025 problems.go reasons.go Challenge Other Languages Go Solution Distribution Install Python, Node, dependencies... One file. That's it. 📦 Speed Interpreted = slower Compiled = blazing fast ⚡ Cross-platform Write once, debug everywhere Build for any OS from any OS 🌍 Parallel tasks Complex threading/async Simple: go func() { } 🚀
  6. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Anatomy of a ‘Good CLI Tool’; GopherCon Africa 2025 reasons.go anatomy.go ❌ Bad CLI Output: ERROR: dependency outdated ERROR: dependency outdated ERROR: dependency outdated Done. ✅ Good CLI Output: ⚠ 3 Critical Updates: • gin v1.7.0 → v1.9.1 (security fix) • jwt v3.2.0 → v4.5.0 (breaking change) • cors v1.3.0 → v1.8.0 (performance) Run: go get -u ./... to update all 🎯 Core Principles: Fast: Nobody wants to wait. If it takes more than 3 seconds, people get frustrated. Clear: Show what matters. Use colors like traffic lights - red for danger, yellow for warnings, green for good. Actionable: Don't just report problems, explain how to fix them. Flexible: Humans want colors and emojis. Machines (CI/CD) want JSON.
  7. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Core Features of ‘Our CLI’ { What: Is version 1.2.0 still good when 2.0.0 exists? Why: New versions fix bugs and add features Risk: Major updates can break your code 📦 Version Check What: Does this code have known vulnerabilities? Why: Hackers know these weaknesses too Risk: Your app = next data breach headline 🛡 Security Scan What: Can I legally use this in my product? Why: Some licenses require you open-source everything Risk: Lawsuits are expensive 📜 License Check What: When was this last updated? Why: Abandoned projects = future problems Risk: No fixes when things break 🕰 Age Analysis GopherCon Africa 2025 anatomy.go features.go }
  8. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Understanding ‘Go Modules’; GopherCon Africa 2025 features.go go.mod What Each Line Means: module: Your project's unique name (like a username) go 1.21: Minimum Go version needed (like "requires Windows 10 or higher") require: External code packages you're using v1.7.0: Exact version you're using (like app version numbers) 🍰 If your project was a cake, go.mod lists all the ingredients (flour v2.1, sugar v1.5, eggs v3.0). Our tool checks if any ingredients are expired or recalled! module github.com/you/project go 1.21 require ( github.com/gin-gonic/gin v1.7.0 github.com/redis/go-redis v9.0.0 golang.org/x/crypto v0.14.0 )
  9. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Utilizing ‘Go Concurrency’; GopherCon Africa 2025 go.mod concurrency.go How Go Makes This Easy // Just add "go" before any function call! go checkDependency(package1) go checkDependency(package2) go checkDependency(package3) That's it! No thread pools, no complex async/await, no callbacks. Just "go"!. It's like having 50 people search different aisles in a supermarket simultaneously, instead of one person checking every aisle alone. Same work, 50x faster! ❌ Without Concurrency (Sequential) Check package 1... (2 seconds) Check package 2... (2 seconds) Check package 3... (2 seconds) ... Check package 50... (2 seconds) Total time: 100 seconds 😴 ✅ With Go Concurrency Check all 50 packages at once! │││││││││││││││││││││││││ │││││││││││││││││││││││││ (all checking in parallel) Total time: 2 seconds! 🚀
  10. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Some Key ‘Go Pattern to Use’; GopherCon Africa 2025 concurrency.go pattern.go 󰍽 The Worker Pool Pattern jobs := make(chan Task, 100) results := make(chan Result, 100) // Spawn workers for i := 0; i < 10; i++ { go worker(jobs, results) } ✨ Why this matters: This pattern lets you process hundreds of items using just 10 workers, preventing system overload! 󰍼 The Options Pattern type Options struct { Format string // "json", "table", "colored" Verbose bool // Show extra details Fix bool // Auto-fix issues } ✨ Why this matters: Makes your tool flexible without having 20 different functions! 󰍹 The Error Check Pattern result, err := doSomething() if err != nil { return fmt.Errorf("failed doing something: %w", err) } // Continue with result… ✨ Why this matters: Go forces you to think about what could go wrong at every step. It's like having guard rails on a mountain road!
  11. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 How To ‘Handle Errors’; GopherCon Africa 2025 pattern.go error.go Bad Error Messages: ❌ "Failed" ❌ "Something went wrong" ❌ "Error: -1" ❌ "Cannot process" These leave users frustrated and helpless! Good Error Messages: ✅ "Cannot read go.mod: file not found Run this command in a Go project" ✅ "GitHub API rate limit reached Wait 10 minutes or use --offline" These tell users what happened AND what to do! ❌ Don't just say "Error occurred" ✅ Say "Error reading go.mod from /path/project: permission denied"
  12. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 How It ‘Will Work’; GopherCon Africa 2025 error.go steps.go Step 1 You type: go-flush in your terminal(assuming it is installed globally) Step 2 Find & Read: Tool finds your go.mod file and reads all dependencies Step 3 Parallel Check: Spawns 50 workers to check each dependency simultaneously Step 4 Gather Intel: Each worker checks versions, security, licenses Step 5 Analyze: Combines all results and calculates health score Step 6 Present: Shows you beautiful, actionable results
  13. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 What Successful ‘Run Looks Like’; GopherCon Africa 2025 steps.go success.go $ go-flush 📦 Go Dependency Health Checker ══════════════════════════════════════════════════ 🔍 Found 23 dependencies 📦 Analyzing 47 dependencies... [████████████████████████████████] 100% Complete 🚨 SECURITY ALERTS (2 Critical) ├─ jwt-go v3.2.0: CVE-2020-26160 (Auth Bypass) │ Fix: upgrade to v4.5.0 └─ websocket v1.4.0: CVE-2020-27813 (DoS Attack) Fix: upgrade to v1.5.1 📊 VERSION STATUS ├─ 12 packages up-to-date ✓ ├─ 8 packages have minor updates └─ 3 packages have MAJOR updates (breaking changes!) 📜 LICENSE SUMMARY ├─ MIT: 12 packages (commercial-friendly ✓) ├─ Apache-2.0: 8 packages (commercial-friendly ✓) └─ GPL-3.0: 3 packages (⚠ requires open-sourcing) HEALTH SCORE: 72/100 - Needs attention 💡 Run with --fix to automatically update safe packages
  14. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Demo Time { Let us dive into the demo, the pieces that make up the whole CLI tool and how it works when coupled together. GopherCon Africa 2025 success.go } demo.go
  15. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 How To Use ‘Our CLI Tool’ { go install github.com/you/tool@latest Perfect for Go developers Always gets latest version 📦 go install brew install your-tool Mac/Linux users love this Auto-updates included 🍺 Homebrew docker run you/tool Perfect for CI/CD Zero installation required 🐳 Docker curl -L url | bash One-liner installation Works everywhere 📎 Direct Download GopherCon Africa 2025 demo.go usage.go }
  16. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Key Lessons ‘You Can Apply’; GopherCon Africa 2025 usage.go lessons.go 🎯 Universal Principles: 1. Start with the user experience: What would make YOU happy to use this? 2. Make errors helpful: Every error should suggest a solution 3. Parallelize everything possible: Modern CPUs have many cores - use them! 4. Respect user's time: Show progress, be fast, cache when possible 💎 Go-Specific Best Practices: • Embrace explicit error handling: It makes code more reliable • Keep interfaces small: Better to have many small interfaces than one big one • Don't be afraid of goroutines: They're lighter than threads • Use the standard library first: It's excellent and well-maintained Remember: Docker, Kubernetes, Terraform, and GitHub CLI are all written in Go. If it's good enough for them...
  17. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 Recommendations; { } GopherCon Africa 2025 lessons.go recommendations.go Official Go Tour: tour.golang.org Go by Example: gobyexample.com Effective Go: golang.org/doc/effective_go Awesome Go: awesome-go.com Go Proverbs: go-proverbs.github.io
  18. 1 2 3 4 5 6 7 8 9 10

    11 12 13 14 CREDITS: This presentation template was created by Slidesgo, including icons by Flaticon, and infographics & images by Freepik Thank You; { ‘Do you have any questions?’ GopherCon Africa 2025 thanks.go new.go } Desmond Obisi 0X_anon_