mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-05-08 19:29:23 -05:00
77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/hatchet-dev/hatchet/api/v1/server/run"
|
|
"github.com/hatchet-dev/hatchet/internal/config/loader"
|
|
"github.com/hatchet-dev/hatchet/pkg/cmdutils"
|
|
)
|
|
|
|
var printVersion bool
|
|
var configDirectory string
|
|
|
|
// rootCmd represents the base command when called without any subcommands
|
|
var rootCmd = &cobra.Command{
|
|
Use: "hatchet-api",
|
|
Short: "hatchet-api runs a Hatchet instance.",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if printVersion {
|
|
fmt.Println(Version)
|
|
os.Exit(0)
|
|
}
|
|
|
|
cf := loader.NewConfigLoader(configDirectory)
|
|
interruptChan := cmdutils.InterruptChan()
|
|
|
|
startServerOrDie(cf, interruptChan)
|
|
},
|
|
}
|
|
|
|
// Version will be linked by an ldflag during build
|
|
var Version string = "v0.1.0-alpha.0"
|
|
|
|
func main() {
|
|
rootCmd.PersistentFlags().BoolVar(
|
|
&printVersion,
|
|
"version",
|
|
false,
|
|
"print version and exit.",
|
|
)
|
|
|
|
rootCmd.PersistentFlags().StringVar(
|
|
&configDirectory,
|
|
"config",
|
|
"",
|
|
"The path the config folder.",
|
|
)
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func startServerOrDie(cf *loader.ConfigLoader, interruptCh <-chan interface{}) {
|
|
// init the repository
|
|
sc, err := cf.LoadServerConfig()
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
ctx, cancel := cmdutils.InterruptContextFromChan(interruptCh)
|
|
defer cancel()
|
|
|
|
runner := run.NewAPIServer(sc)
|
|
|
|
err = runner.Run(ctx)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|