Command-Line Programs
Usage Output
A usage message shows the accepted command shape when input is incomplete or unclear.
usage text
Usage text is a short guide that tells the user how to call a command.
Usage Output
usage_output.go
Replay: real traced execution (multi-file project)
package main
import "fmt"
func usage(command string) []string {
lines := []string{
"usage: tool " + command + " [options]",
" --help show help",
" --limit N choose a small limit",
}
return lines
}
func main() {
var command = "report"
lines := usage(command)
for index, line := range lines {
fmt.Println(index, line)
}
fmt.Println("lineCount=", len(lines))
}
package main
import "fmt"
func usage(command string) []string {
lines := []string{
"usage: tool " + command + " [options]",
" --help show help",
" --limit N choose a small limit",
}
return lines
}
func main() {
var command = "build"
lines := usage(command)
for index, line := range lines {
fmt.Println(index, line)
}
fmt.Println("lineCount=", len(lines))
}
package main
import "fmt"
func usage(command string) []string {
lines := []string{
"usage: tool " + command + " [options]",
" --help show help",
" --limit N choose a small limit",
}
return lines
}
func main() {
var command = "test"
lines := usage(command)
for index, line := range lines {
fmt.Println(index, line)
}
fmt.Println("lineCount=", len(lines))
}
command ← "report"
14func main() {15 var command→ "report" = "report" //@command="build", "test"16 lines := usage(command"report")lines ← []string{"usage: tool report [options]", " --help show help", " --limit N choose a small limit"}
5func usage(command"report" string) []string {6 lines→ []string{"usage: tool report [options]", " --help show help", " --limit N choose a small limit"} := []string{7 "usage: tool " + command"report" + " [options]",8 " --help show help",9 " --limit N choose a small limit",10 }11 return lines[]string{"usage: tool report [options]", " --help show help", " --limit N choose a small limit"}12}lines ← []string{"usage: tool report [options]", " --help show help", " --limit N choose a small limit"}
15var command = "report" //@command="build", "test"16lines→ []string{"usage: tool report [options]", " --help show help", " --limit N choose a small limit"} := usage(command"report")for index, line := range lines
pass 1 of 318for index0, line"usage: tool report [options]" := range lines[]string{"usage: tool report [options]", " --help show help", " --limit N choose a small limit"} {19 fmt.Println(index0, line"usage: tool report [options]")20}output0 usage: tool report [options]All 3 passes — pass 1 is the card above pass indexline1 0 "usage: tool report [options]" 2 1 " --help show help" 3 2 " --limit N choose a small limit" fmt.Println("lineCount=", len(lines))
20 }21 fmt.Println("lineCount=", len(lines[]string{"usage: tool report [options]", " --help show help", " --limit N choose a small limit"}))22}outputlineCount= 3
command ← "build"
14func main() {15 var command→ "build" = "build"16 lines := usage(command"build")lines ← []string{"usage: tool build [options]", " --help show help", " --limit N choose a small limit"}
5func usage(command"build" string) []string {6 lines→ []string{"usage: tool build [options]", " --help show help", " --limit N choose a small limit"} := []string{7 "usage: tool " + command"build" + " [options]",8 " --help show help",9 " --limit N choose a small limit",10 }11 return lines[]string{"usage: tool build [options]", " --help show help", " --limit N choose a small limit"}12}lines ← []string{"usage: tool build [options]", " --help show help", " --limit N choose a small limit"}
15var command = "build"16lines→ []string{"usage: tool build [options]", " --help show help", " --limit N choose a small limit"} := usage(command"build")for index, line := range lines
pass 1 of 318for index0, line"usage: tool build [options]" := range lines[]string{"usage: tool build [options]", " --help show help", " --limit N choose a small limit"} {19 fmt.Println(index0, line"usage: tool build [options]")20}output0 usage: tool build [options]All 3 passes — pass 1 is the card above pass indexline1 0 "usage: tool build [options]" 2 1 " --help show help" 3 2 " --limit N choose a small limit" fmt.Println("lineCount=", len(lines))
20 }21 fmt.Println("lineCount=", len(lines[]string{"usage: tool build [options]", " --help show help", " --limit N choose a small limit"}))22}outputlineCount= 3
command ← "test"
14func main() {15 var command→ "test" = "test"16 lines := usage(command"test")lines ← []string{"usage: tool test [options]", " --help show help", " --limit N choose a small limit"}
5func usage(command"test" string) []string {6 lines→ []string{"usage: tool test [options]", " --help show help", " --limit N choose a small limit"} := []string{7 "usage: tool " + command"test" + " [options]",8 " --help show help",9 " --limit N choose a small limit",10 }11 return lines[]string{"usage: tool test [options]", " --help show help", " --limit N choose a small limit"}12}lines ← []string{"usage: tool test [options]", " --help show help", " --limit N choose a small limit"}
15var command = "test"16lines→ []string{"usage: tool test [options]", " --help show help", " --limit N choose a small limit"} := usage(command"test")for index, line := range lines
pass 1 of 318for index0, line"usage: tool test [options]" := range lines[]string{"usage: tool test [options]", " --help show help", " --limit N choose a small limit"} {19 fmt.Println(index0, line"usage: tool test [options]")20}output0 usage: tool test [options]All 3 passes — pass 1 is the card above pass indexline1 0 "usage: tool test [options]" 2 1 " --help show help" 3 2 " --limit N choose a small limit" fmt.Println("lineCount=", len(lines))
20 }21 fmt.Println("lineCount=", len(lines[]string{"usage: tool test [options]", " --help show help", " --limit N choose a small limit"}))22}outputlineCount= 3