gouick/cmd/root.go

80 lines
1.9 KiB
Go

/*
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
*/
package cmd
import (
"os"
"git.home.m-and-m.ovh/mderasse/boot/helpers/dependencies"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
var version = "0.0.1"
var verbose = false
var acceptAll = false
var dependencyList = []dependencies.DependencyInterface{
dependencies.Git{},
dependencies.Golang{},
dependencies.Swagger{},
}
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "boot",
Short: "Boot is a toolbox app to bootstrap quickly a Go-Swagger API",
Long: `Boot is a toolbox app to bootstrap quickly a Go-Swagger API.
It will:
- Auto-Update
- Download dependencies (go-swagger, ...)
- Initialize an API with default middlewares
- Generate Models / Controlers
- Generate Database structs
- ....`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if verbose {
log.SetLevel(log.DebugLevel)
}
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
rootCmd.PersistentFlags().BoolVarP(&acceptAll, "yes", "y", false, "accept all change, disable interactive process")
}
// checkDependencies
func checkDependencies() bool {
for _, dependency := range dependencyList {
isSupported, err := dependency.IsVersionSupported()
if err != nil {
log.Errorf("Fail to check %s version. The following error happen: %s", dependency.GetName(), err.Error())
return false
}
if isSupported {
continue
}
log.Infof("Dependency %s missing or not supported, please run the 'upgrade' command.", dependency.GetName())
}
return true
}