Stage 1 · Code
Your First Real Program
Reading Input
Parse command-line arguments, read flags, and scan interactive input safely.
os.Args
os.Args is a slice of strings containing the program name and all command-line arguments. os.Args[0] is always the executable name; arguments start at os.Args[1].
The flag Package
The flag package parses named flags like -title "Buy milk". Flags can be booleans, integers, strings, or durations. flag.Parse() must be called before reading flag values.
Subcommands with flag.FlagSet
flag.FlagSet creates an independent flag set for each subcommand. This lets add and list have different flags without interfering with each other.
Reading stdin
bufio.Scanner reads stdin line by line without loading the whole input into memory. This is the correct approach for pipelines and interactive programs.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.