gouick/cmd/root.go
Matthieu 'JP' DERASSE 3d878c050d
All checks were successful
continuous-integration/drone/push Build is passing
fix(path): Fix package name after git server migration
2022-11-26 22:36:00 +00:00

77 lines
2.0 KiB
Go

/*
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
*/
package cmd
import (
"os"
"git.dev.m-and-m.ovh/mderasse/gouick/helpers/dependencies"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
const 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 / Controllers
- 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() {
if err := rootCmd.Execute(); 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 will go through all the dependencies a check if they are installed and respect minimum version.
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
}