114 lines
2.2 KiB
Go
114 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"arno/skeletor/config"
|
|
"arno/skeletor/service"
|
|
"arno/skeletor/tool"
|
|
"arno/skeletor/crontab"
|
|
"arno/skeletor/repository"
|
|
"arno/skeletor/entity"
|
|
|
|
"gorm.io/gorm"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
// Chargement de la configuration
|
|
myconfig, mydb, _ := config.NewConfig("config/config.ini", false)
|
|
|
|
// On s'assure qu'il y a une commande à executer
|
|
args := os.Args[1:]
|
|
if len(args) == 0 {
|
|
Help(mydb)
|
|
return
|
|
}
|
|
|
|
// On récupére la commande et ses paramètres
|
|
cmd := args[0]
|
|
params := args[1:]
|
|
|
|
// On s'assure que la commande existe bien
|
|
var command entity.Command
|
|
result := mydb.First(&command, "name = ?", cmd)
|
|
if result.RowsAffected == 0 {
|
|
Help(mydb)
|
|
return
|
|
}
|
|
|
|
// Creation des services
|
|
ctn := service.NewContainer()
|
|
ctn.Provide(config.ServiceName, config.ServiceProvider(myconfig))
|
|
ctn.Provide(repository.ServiceName, repository.ServiceProvider(mydb))
|
|
|
|
if len(params) == 0 {
|
|
_, err := crontab.Call(cmd, ctn)
|
|
if err != nil {
|
|
tool.LogFatal(err.Error())
|
|
|
|
tool.LogInfo(command.Name)
|
|
tool.Log(command.Description)
|
|
tool.Log("")
|
|
}
|
|
}
|
|
|
|
if len(params) == 1 {
|
|
_, err := crontab.Call(cmd, ctn, params[0])
|
|
if err != nil {
|
|
tool.LogFatal(err.Error())
|
|
|
|
tool.LogInfo(command.Name)
|
|
tool.Log(command.Description)
|
|
tool.Log("")
|
|
}
|
|
}
|
|
|
|
if len(params) == 2 {
|
|
_, err := crontab.Call(cmd, ctn, params[0], params[1])
|
|
if err != nil {
|
|
tool.LogFatal(err.Error())
|
|
|
|
tool.LogInfo(command.Name)
|
|
tool.Log(command.Description)
|
|
tool.Log("")
|
|
}
|
|
}
|
|
|
|
if len(params) == 3 {
|
|
_, err := crontab.Call(cmd, ctn, params[0], params[1], params[3])
|
|
if err != nil {
|
|
tool.LogFatal(err.Error())
|
|
}
|
|
}
|
|
|
|
if len(params) == 4 {
|
|
_, err := crontab.Call(cmd, ctn, params[0], params[1], params[3], params[4])
|
|
if err != nil {
|
|
tool.LogFatal(err.Error())
|
|
}
|
|
}
|
|
|
|
if len(params) == 5 {
|
|
_, err := crontab.Call(cmd, ctn, params[0], params[1], params[3], params[4], params[5])
|
|
if err != nil {
|
|
tool.LogFatal(err.Error())
|
|
}
|
|
}
|
|
|
|
tool.Log("")
|
|
}
|
|
|
|
func Help(mydb *gorm.DB) {
|
|
tool.LogTitle("COMMANDES")
|
|
tool.Log("Liste des commandes possibles")
|
|
tool.Log("")
|
|
|
|
var commands []entity.Command
|
|
mydb.Find(&commands)
|
|
|
|
for _, command := range commands {
|
|
tool.LogInfo(command.Name)
|
|
tool.Log(command.Description)
|
|
tool.Log("")
|
|
}
|
|
}
|