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

command
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))
}
  1. command ← "report"

    14func main() {15  var command→ "report" = "report" //@command="build", "test"16  lines := usage(command"report")
  2. 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}
  3. 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")
  4. for index, line := range lines

    pass 1 of 3
    18for 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
    passindexline
    10"usage: tool report [options]"
    21" --help show help"
    32" --limit N choose a small limit"
  5. 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
  1. command ← "build"

    14func main() {15  var command→ "build" = "build"16  lines := usage(command"build")
  2. 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}
  3. 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")
  4. for index, line := range lines

    pass 1 of 3
    18for 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
    passindexline
    10"usage: tool build [options]"
    21" --help show help"
    32" --limit N choose a small limit"
  5. 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
  1. command ← "test"

    14func main() {15  var command→ "test" = "test"16  lines := usage(command"test")
  2. 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}
  3. 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")
  4. for index, line := range lines

    pass 1 of 3
    18for 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
    passindexline
    10"usage: tool test [options]"
    21" --help show help"
    32" --limit N choose a small limit"
  5. 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