babillard/cmd/cmd.go

68 lines
1.4 KiB
Go
Raw Permalink Normal View History

package cmd
import (
"flag"
"os"
"codeberg.org/vlbeaudoin/couleuvre"
"git.agecem.com/agecem/babillard/config"
"git.agecem.com/agecem/babillard/handlers"
)
var cfg config.Config
func Cfg() config.Config { return cfg }
func init() {
flag.StringVar(&cfg.ServerContenuDir, ServerContenuDirName, ServerContenuDirDefault, ServerContenuDirDescription)
flag.IntVar(&cfg.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(Cfg())
return nil
}
func Execute() error {
app := couleuvre.NewApp("BABILLARD_", ".", "_")
if err := app.Parse(&cfg); 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
}