pye/cmd/root.go

51 lines
1.1 KiB
Go
Raw Normal View History

2024-10-13 16:16:19 +03:00
package cmd
import (
"fmt"
"os"
2024-10-13 16:38:13 +03:00
"git.a71.su/Andrew71/pye/auth"
2024-10-13 16:16:19 +03:00
"git.a71.su/Andrew71/pye/config"
"git.a71.su/Andrew71/pye/logging"
"git.a71.su/Andrew71/pye/storage"
"git.a71.su/Andrew71/pye/storage/sqlite"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "pye",
Short: "Pye is a simple JWT system",
Long: `A bare-bones authentication system built by Andrew71 as an assignment`,
}
var (
cfgFile string
cfgDb string
debugMode *bool
)
func initConfig() {
logging.LogInit(*debugMode)
2024-10-13 16:38:13 +03:00
config.MustLoadConfig(cfgFile)
2024-10-13 16:16:19 +03:00
if cfgDb != "" {
config.Cfg.SQLiteFile = cfgDb
}
2024-10-13 16:38:13 +03:00
auth.MustLoadKey()
2024-10-13 16:16:19 +03:00
storage.Data = sqlite.MustLoadSQLite(config.Cfg.SQLiteFile)
}
func init() {
cobra.OnInitialize(initConfig)
2024-10-13 16:38:13 +03:00
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "config.json", "config file")
2024-10-13 16:16:19 +03:00
rootCmd.PersistentFlags().StringVar(&cfgDb, "db", "", "database to use")
debugMode = rootCmd.PersistentFlags().BoolP("debug", "d", false, "enable debug mode")
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}