Victor Lacasse-Beaudoin
72ff53f846
bump: couleuvre -> `v0.10.0` Move `couleuvre.NewApp` to `cmd.init` Make flags target `&cmd.app.Config` Fix `ServerCmdExecuter`'s `RunServer` parameters Fix call to `app.Parse` in `cmd.Execute` BREAKING: Remove `cmd.Cfg()` BREAKING: Remove `cmd.cfg config.Config`
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
|
|
"codeberg.org/vlbeaudoin/couleuvre"
|
|
"git.agecem.com/agecem/babillard/config"
|
|
"git.agecem.com/agecem/babillard/handlers"
|
|
)
|
|
|
|
var app couleuvre.App[config.Config]
|
|
|
|
func init() {
|
|
app = couleuvre.NewApp[config.Config]("BABILLARD_", ".", "_")
|
|
|
|
flag.StringVar(&app.Config.ServerContenuDir, ServerContenuDirName, ServerContenuDirDefault, ServerContenuDirDescription)
|
|
flag.IntVar(&app.Config.ServerPort, ServerPortName, ServerPortDefault, ServerPortDescription)
|
|
}
|
|
|
|
const (
|
|
ServerContenuDirName = "servercontenudir"
|
|
ServerContenuDirDefault = "contenu"
|
|
ServerContenuDirDescription = "Répertoire du contenu à exposer"
|
|
|
|
ServerPortName = "serverport"
|
|
ServerPortDefault int = 8080
|
|
ServerPortDescription = "Port réseau à utiliser pour le serveur"
|
|
)
|
|
|
|
const (
|
|
ServerCmdName = "server"
|
|
ServerCmdDesc = "Démarrer le serveur web"
|
|
)
|
|
|
|
func ServerCmdExecuter() error {
|
|
handlers.RunServer(app.Config.ServerContenuDir, app.Config.ServerPort)
|
|
return nil
|
|
}
|
|
|
|
func Execute() error {
|
|
if err := app.Parse(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := app.NewCommand(ServerCmdName, ServerCmdDesc, ServerCmdExecuter); err != nil {
|
|
return err
|
|
}
|
|
|
|
var commandName string
|
|
if len(os.Args) > 1 {
|
|
commandName = flag.Arg(0)
|
|
}
|
|
|
|
cmd, err := app.ParseCommand(commandName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := cmd.Execute(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|