feat(dependencies): Implement base of the dependency system
This commit is contained in:
36
cmd/generate.go
Normal file
36
cmd/generate.go
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.home.m-and-m.ovh/mderasse/boot/helpers"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// generateCmd represents the generate command
|
||||
var generateCmd = &cobra.Command{
|
||||
Use: "generate",
|
||||
Short: "Generate all the files (API, DB, ...)",
|
||||
Long: `Generate will automatically create all the files of the Project.
|
||||
You can also generate files for each 'modules' by using the command bellows`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if isStrap, err := helpers.IsStrapProject(); err != nil {
|
||||
|
||||
fmt.Print("Fail to check if we are in a Strap Directory")
|
||||
|
||||
} else if !isStrap {
|
||||
fmt.Printf("You are not in a Strap Project directory\n")
|
||||
return
|
||||
}
|
||||
fmt.Println("generate called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(generateCmd)
|
||||
}
|
24
cmd/generateAPI.go
Normal file
24
cmd/generateAPI.go
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// apiCmd represents the api command
|
||||
var apiCmd = &cobra.Command{
|
||||
Use: "api",
|
||||
Short: "Generate Go-Swagger Files and Controllers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("api called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
generateCmd.AddCommand(apiCmd)
|
||||
}
|
24
cmd/generateDB.go
Normal file
24
cmd/generateDB.go
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// dbCmd represents the db command
|
||||
var dbCmd = &cobra.Command{
|
||||
Use: "db",
|
||||
Short: "Generate Database Struct from pkg/dbmodels/schema.yaml",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("db called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
generateCmd.AddCommand(dbCmd)
|
||||
}
|
24
cmd/generateDocker.go
Normal file
24
cmd/generateDocker.go
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// dockerCmd represents the docker command
|
||||
var dockerCmd = &cobra.Command{
|
||||
Use: "docker",
|
||||
Short: "Generate Dockerfile for API & Workers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("docker called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
generateCmd.AddCommand(dockerCmd)
|
||||
}
|
24
cmd/generateHelm.go
Normal file
24
cmd/generateHelm.go
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// helmCmd represents the helm command
|
||||
var helmCmd = &cobra.Command{
|
||||
Use: "helm",
|
||||
Short: "Generate Kubernetes Helm chart for API & Workers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("helm called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
generateCmd.AddCommand(helmCmd)
|
||||
}
|
25
cmd/generateHelp.go
Normal file
25
cmd/generateHelp.go
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// helpCmd represents the help command
|
||||
var helpCmd = &cobra.Command{
|
||||
Use: "help",
|
||||
Short: "Show that help",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := generateCmd.Help()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
generateCmd.AddCommand(helpCmd)
|
||||
}
|
24
cmd/generateLauncher.go
Normal file
24
cmd/generateLauncher.go
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// launcherCmd represents the launcher command
|
||||
var launcherCmd = &cobra.Command{
|
||||
Use: "launcher",
|
||||
Short: "Generate Launcher Bash script",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("launcher called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
generateCmd.AddCommand(launcherCmd)
|
||||
}
|
24
cmd/generateMakefile.go
Normal file
24
cmd/generateMakefile.go
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// makefileCmd represents the makefile command
|
||||
var makefileCmd = &cobra.Command{
|
||||
Use: "makefile",
|
||||
Short: "Generate Makefile",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("makefile called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
generateCmd.AddCommand(makefileCmd)
|
||||
}
|
61
cmd/init.go
Normal file
61
cmd/init.go
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// initCmd represents the init command
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize a new project",
|
||||
Long: `Initialize a new project by creating a new directory and:
|
||||
- Initialize a Git Repository
|
||||
- Create a Go-Swagger Struct
|
||||
- Add default routes
|
||||
- Generate the API.
|
||||
|
||||
That command is Interactive or can be control through args`,
|
||||
Run: runInitAction,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(initCmd)
|
||||
}
|
||||
|
||||
func runInitAction(cmd *cobra.Command, args []string) {
|
||||
|
||||
log.Debugf("Starting command Init")
|
||||
|
||||
log.Debugf("Checking dependecies")
|
||||
|
||||
// isDependeciesOk, err := helpers.CheckDependencies()
|
||||
// if err != nil {
|
||||
// log.Error(err.Error())
|
||||
// return
|
||||
// } else if isDependeciesOk {
|
||||
// log.Error("Dependencies are not repescted")
|
||||
// return
|
||||
// }
|
||||
|
||||
// if isGoProject, err := helpers.IsGoProject(); err != nil {
|
||||
// log.Error("An error occured when checking your directory.")
|
||||
// return
|
||||
// } else if isGoProject {
|
||||
// log.Error("Cannot initialize a new project because you are already in a Golang Project Directory.")
|
||||
// return
|
||||
// }
|
||||
|
||||
// if isStrapProject, err := helpers.IsStrapProject(); err != nil {
|
||||
// log.Error("An error occured when checking your directory.")
|
||||
// return
|
||||
// } else if isStrapProject {
|
||||
// log.Error("Cannot initialize a new project because you are already in a Strap Project Directory.")
|
||||
// return
|
||||
// }
|
||||
}
|
51
cmd/root.go
Normal file
51
cmd/root.go
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var verbose = false
|
||||
var acceptAll = false
|
||||
|
||||
// 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")
|
||||
}
|
24
cmd/test.go
Normal file
24
cmd/test.go
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// testCmd represents the test command
|
||||
var testCmd = &cobra.Command{
|
||||
Use: "test",
|
||||
Short: "Launch Test",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("test called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(testCmd)
|
||||
}
|
116
cmd/upgrade.go
Normal file
116
cmd/upgrade.go
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.home.m-and-m.ovh/mderasse/boot/helpers"
|
||||
"git.home.m-and-m.ovh/mderasse/boot/helpers/dependencies"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// upgradeCmd represents the upgrade command
|
||||
var upgradeCmd = &cobra.Command{
|
||||
Use: "upgrade",
|
||||
Short: "Upgrade all development dependencies",
|
||||
Long: `Upgrade the following dependencies:
|
||||
- Golang
|
||||
- Go Swagger
|
||||
- ...
|
||||
`,
|
||||
Run: runUpgradeAction,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(upgradeCmd)
|
||||
}
|
||||
|
||||
func runUpgradeAction(cmd *cobra.Command, args []string) {
|
||||
|
||||
dependencies := []dependencies.Dependency{dependencies.Golang{}}
|
||||
|
||||
for _, dependency := range dependencies {
|
||||
|
||||
log.Debugf("Checking if dependency %s is supported", dependency.GetName())
|
||||
|
||||
isSupported, err := dependency.IsVersionSupported()
|
||||
if err != nil {
|
||||
log.Errorf("Fail to check %s version. The following error happen: %s", dependency.GetName(), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if isSupported {
|
||||
log.Infof("%s version is supported, continue", dependency.GetName())
|
||||
continue
|
||||
}
|
||||
|
||||
log.Infof("Your %s is not supported.", dependency.GetName())
|
||||
|
||||
if !acceptAll {
|
||||
log.Infof("Do you want to install the following version: %s", dependency.GetMinimumVersion())
|
||||
|
||||
answer := helpers.YesOrNoInput()
|
||||
if !answer {
|
||||
log.Warnf("Skipping installation of %s. Some part of the application might not be able to work correctly!", dependency.GetName())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug("Trying to find the best installation directory")
|
||||
|
||||
installDirectory, err := dependency.GetInstallDirectory()
|
||||
if err != nil {
|
||||
log.Errorf("Fail to compute the %s install directory. The following error happen: %s", dependency.GetName(), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// ask user if the path is correct, else ask new path and check validity
|
||||
if !acceptAll {
|
||||
log.Infof("Do you want to install %s in the directory %s ?", dependency.GetName(), installDirectory)
|
||||
|
||||
answer := helpers.YesOrNoInput()
|
||||
if !answer {
|
||||
log.Infof("Where do you want to install %s ?", dependency.GetName())
|
||||
installDirectory = helpers.IsValidPathInput()
|
||||
}
|
||||
|
||||
} else {
|
||||
log.Infof("Installing %s in the following directory: %s", dependency.GetName(), installDirectory)
|
||||
}
|
||||
|
||||
log.Debug("Checking directory and creating it if needed")
|
||||
|
||||
// check if the path is ok, else ask user for new path if we are in a interactive mode, else stop
|
||||
err = helpers.CheckAndCreateDir(installDirectory)
|
||||
if err != nil {
|
||||
log.Errorf("Impossible to create the instalation directory for %s", dependency.GetName())
|
||||
if acceptAll {
|
||||
return
|
||||
}
|
||||
log.Infof("Where do you want to install %s ?", dependency.GetName())
|
||||
installDirectory = helpers.IsValidPathInput()
|
||||
}
|
||||
|
||||
log.Infof("The following command will be executed:\n%s", dependency.DescribeInstall(installDirectory))
|
||||
log.Info("Do you want to continue ?")
|
||||
answer := helpers.YesOrNoInput()
|
||||
if !answer {
|
||||
log.Warnf("Skipping installation of %s. Some part of the application might not be able to work correctly!", dependency.GetName())
|
||||
continue
|
||||
}
|
||||
|
||||
log.Debug("Starting the installation")
|
||||
|
||||
err = dependency.Install(installDirectory)
|
||||
if err != nil {
|
||||
log.Errorf("Fail to install %s version. The following error happen: %s", dependency.GetName(), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("%s successfully installed", dependency.GetName())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user