2026-05-26 15:31:44 +02:00

44 lines
734 B
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"printer.backend/internal/config"
)
var (
cfgFile string
cfg *config.Config
)
var rootCmd = &cobra.Command{
Use: "printer-backend",
Short: "Alox printer backend CLI",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if cfgFile == "" {
cfg = config.Default()
return nil
}
var err error
cfg, err = config.Load(cfgFile)
return err
},
SilenceUsage: true,
}
// Execute runs the root command.
func Execute() error {
return rootCmd.Execute()
}
func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "path to JSON config file")
}
func exitWithError(err error) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}