package cmd import ( "chronical/service" "fmt" "os" "os/signal" "syscall" "time" "chronical/config" "github.com/rs/zerolog/log" "github.com/spf13/cobra" ) var rootCommand = &cobra.Command{ Use: "chronical", Short: "Runs the chronical daemon.", PreRun: func(cmd *cobra.Command, args []string) {}, Run: func(cmd *cobra.Command, args []string) { startService() }, } var versionCommand = &cobra.Command{ Use: "version", Short: "Prints the current executable version and exits.", Run: func(cmd *cobra.Command, _ []string) { fmt.Printf("%s | Version: %s Build: %s | Copyright © %d William Gill\n", config.Project, config.Version, config.Build, time.Now().Year()) }, } func Execute() { if err := rootCommand.Execute(); err != nil { log.Fatal().Err(err).Msgf("failed to execute command.") } } func init() { rootCommand.PersistentFlags().IntVarP(&config.WorkerID, "worker-id", "w", 1, "Specify the Worker ID between 1 and 1023 - Default is 1.") rootCommand.PersistentFlags().IntVarP(&config.Epoch, "epoch", "e", 2025, "Specify the Epoch Year - Default is 2025.") rootCommand.AddCommand(versionCommand) } func startService() { service.SnowflakeServer() // Set up signal handling for graceful shutdown sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) // Wait for interrupt signal <-sigChan log.Info().Msg("Received interrupt signal, shutting down gracefully...") }