Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Building a Simple CLI Tool | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 40 of 60

·Go

Building a Simple CLI Tool – Argument Parsing

15 minutes

Course progress67%

Argument Parsing with flag

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

import "flag"

func main() {
    name := flag.String("name", , )
    repeat := flag.Int(, , )
    flag.Parse()
     i := ; i < *repeat; i++ {
        fmt.Printf(, *name)
    }
}
"world"
"name to greet"
"n"
1
"how many times to greet"
for
0
"Hello, %s! "

Run:

$ go run greet.go -name=Bob -n=3
Hello, Bob!
Hello, Bob!
Hello, Bob!

Sub‑commands with Cobra (see lesson‑23)

Info

Prefer the standard flag package for tiny tools; use Cobra for complex CLIs.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonTesting Concurrency – Race Detector and `testing`Continue to lesson 41Logging & Structured Tracing with OpenTelemetryBack to Go Programming Bootcamp curriculum