help_command.go 640 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. )
  6. func BuildHelpCommand() *Command {
  7. return &Command{
  8. Name: "help",
  9. FlagSet: flag.NewFlagSet("help", flag.ExitOnError),
  10. UsageCommand: "ginkgo help <COMMAND>",
  11. Usage: []string{
  12. "Print usage information. If a command is passed in, print usage information just for that command.",
  13. },
  14. Command: printHelp,
  15. }
  16. }
  17. func printHelp(args []string, additionalArgs []string) {
  18. if len(args) == 0 {
  19. usage()
  20. } else {
  21. command, found := commandMatching(args[0])
  22. if !found {
  23. complainAndQuit(fmt.Sprintf("Unknown command: %s", args[0]))
  24. }
  25. usageForCommand(command, true)
  26. }
  27. }