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 }