github.com/zaquestion/lab@v0.25.1/main.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/rsteube/carapace"
     7  	"github.com/zaquestion/lab/cmd"
     8  	"github.com/zaquestion/lab/internal/config"
     9  	lab "github.com/zaquestion/lab/internal/gitlab"
    10  )
    11  
    12  // version gets set on releases during build by goreleaser.
    13  var version = "master"
    14  
    15  func main() {
    16  	cmd.Version = version
    17  	initSkipped := skipInit()
    18  	if !initSkipped {
    19  		h, u, t, ca, skipVerify := config.LoadMainConfig()
    20  
    21  		if ca != "" {
    22  			lab.InitWithCustomCA(h, u, t, ca)
    23  		} else {
    24  			lab.Init(h, u, t, skipVerify)
    25  		}
    26  	}
    27  	cmd.Execute(initSkipped)
    28  }
    29  
    30  func skipInit() bool {
    31  	nArgs := len(os.Args)
    32  	if nArgs <= 1 {
    33  		return false
    34  	}
    35  	switch os.Args[nArgs-1] {
    36  	case "-h", "--help":
    37  		return true
    38  	}
    39  	switch os.Args[1] {
    40  	case "-v", "--version", "version":
    41  		return true
    42  	case "-h", "--help", "help":
    43  		return true
    44  	case "completion":
    45  		return true
    46  	case "_carapace":
    47  		return !carapace.IsCallback()
    48  	default:
    49  		return false
    50  	}
    51  }