feat(multiple): Add version command, improve dependencies file managment

This commit is contained in:
Matthieu 'JP' DERASSE
2022-07-16 22:16:29 +00:00
parent ce433832f7
commit 5b50b5409b
9 changed files with 182 additions and 44 deletions

View File

@ -7,7 +7,6 @@ package cmd
import (
"fmt"
"git.home.m-and-m.ovh/mderasse/boot/helpers"
"github.com/spf13/cobra"
)
@ -19,14 +18,6 @@ var generateCmd = &cobra.Command{
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")
},
}

View File

@ -5,6 +5,9 @@ Copyright © 2022 Matthieu Derasse <git@derasse.fr>
package cmd
import (
"os"
"git.home.m-and-m.ovh/mderasse/boot/helpers"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
@ -28,20 +31,79 @@ func init() {
rootCmd.AddCommand(initCmd)
}
// runInitAction
// Steps:
// 1 - Check that we have the dependencies
// 2 - Check that we are not in project directory
// 3 - Ask info to the user
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 !checkDependencies() {
return
}
// Get current path
currentPath, err := os.Getwd()
if err != nil {
log.Errorf("Fail to get current path. The following error happen: %s", err.Error())
return
}
log.Debugf("Working in directory: %s", currentPath)
// Check if we are in goguik directory
log.Debug("Checking if we are in the same directory as Goguik")
isGoguikDir, err := helpers.IsGoguikDirectory(currentPath)
if err != nil {
log.Errorf("Fail to check if we are in goguik directory. The following error happen: %s", err.Error())
return
}
if isGoguikDir {
log.Error("You cannot initialize a new project in the same dir than goguik\nGoguik should be added to your path")
return
}
// Check if we are in a go project
log.Debug("Checking if we are in a golang project")
isGoProject, err := helpers.IsGoProject(currentPath)
if err != nil {
log.Errorf("Fail to check if we are in a go project. The following error happen: %s", err.Error())
return
}
if isGoProject {
log.Error("You cannot initialize a new project in an already golang project")
return
}
// Check if we are in a goguik project
log.Debug("Checking if we are in a goguik project")
isGoguikProject, err := helpers.IsGoguikProject(currentPath)
if err != nil {
log.Errorf("Fail to check if we are in a goguik project. The following error happen: %s", err.Error())
return
}
if isGoguikProject {
log.Error("You cannot initialize a new project in an already goguik project")
return
}
// XXX:
// Check we are in gopath or ask for the gomod name
// Create directory
// Move to dir
// git init
// create .goguik
// move templated file
// if isGoProject, err := helpers.IsGoProject(); err != nil {
// log.Error("An error occured when checking your directory.")

View File

@ -13,6 +13,7 @@ import (
log "github.com/sirupsen/logrus"
)
var version = "0.0.1"
var verbose = false
var acceptAll = false
var dependencyList = []dependencies.Dependency{
@ -55,3 +56,24 @@ 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
}

27
cmd/version.go Normal file
View File

@ -0,0 +1,27 @@
/*
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Show goguik version",
Run: runVersion,
}
func init() {
rootCmd.AddCommand(versionCmd)
}
func runVersion(cmd *cobra.Command, args []string) {
// could probably have a look at runtime/debug
fmt.Printf("version: v%s\n", version)
}