main.go 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "os"
  7. "github.com/hashicorp/consul/command"
  8. "github.com/hashicorp/consul/lib"
  9. _ "github.com/hashicorp/consul/service_os"
  10. "github.com/mitchellh/cli"
  11. )
  12. func init() {
  13. lib.SeedMathRand()
  14. }
  15. func main() {
  16. os.Exit(realMain())
  17. }
  18. func realMain() int {
  19. log.SetOutput(ioutil.Discard)
  20. args := os.Args[1:]
  21. for _, arg := range args {
  22. if arg == "--" {
  23. break
  24. }
  25. if arg == "-v" || arg == "--version" {
  26. args = []string{"version"}
  27. break
  28. }
  29. }
  30. ui := &cli.BasicUi{Writer: os.Stdout, ErrorWriter: os.Stderr}
  31. cmds := command.Map(ui)
  32. var names []string
  33. for c := range cmds {
  34. names = append(names, c)
  35. }
  36. cli := &cli.CLI{
  37. Args: args,
  38. Commands: cmds,
  39. Autocomplete: true,
  40. Name: "consul",
  41. HelpFunc: cli.FilteredHelpFunc(names, cli.BasicHelpFunc("consul")),
  42. }
  43. exitCode, err := cli.Run()
  44. if err != nil {
  45. fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
  46. return 1
  47. }
  48. return exitCode
  49. }