github.com/kjdelisle/consul@v1.4.5/main.go (about)

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