started with serve command, yet incomplete

This commit is contained in:
2024-12-20 18:59:59 +01:00
committed by T.v.Dein
parent 37ca653461
commit 7bc30da609
8 changed files with 305 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/tlinden/anydb/app"
"github.com/tlinden/anydb/cfg"
"github.com/tlinden/anydb/output"
"github.com/tlinden/anydb/rest"
)
func Set(conf *cfg.Config) *cobra.Command {
@@ -311,3 +312,23 @@ func Man(conf *cfg.Config) *cobra.Command {
return cmd
}
func Serve(conf *cfg.Config) *cobra.Command {
var cmd = &cobra.Command{
Use: "serve [-l host:port]",
Short: "run REST API listener",
Long: `run REST API listener`,
RunE: func(cmd *cobra.Command, args []string) error {
// errors at this stage do not cause the usage to be shown
cmd.SilenceUsage = true
rest.Runserver(conf, nil)
return nil
},
}
cmd.PersistentFlags().StringVarP(&conf.Listen, "listen", "l", "localhost:8787", "host:port")
return cmd
}

View File

@@ -83,6 +83,7 @@ func Execute() {
rootCmd.AddCommand(Del(&conf))
rootCmd.AddCommand(Export(&conf))
rootCmd.AddCommand(Import(&conf))
rootCmd.AddCommand(Serve(&conf))
rootCmd.AddCommand(Man(&conf))
err = rootCmd.Execute()