You've already forked panic-cli
mirror of
https://github.com/Print-and-Panic/panic-cli.git
synced 2026-01-21 10:17:41 -08:00
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
// cmd/root.go
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/Print-and-Panic/panic-cli/internal/config"
|
|
"github.com/Print-and-Panic/panic-cli/internal/platform"
|
|
"github.com/Print-and-Panic/panic-cli/internal/system"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var cfgFile string
|
|
var dryRun bool
|
|
|
|
var RootCmd = &cobra.Command{
|
|
Use: "panic-cli",
|
|
Short: "A set of tools to run the Print and Panic YouTube channel",
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
if dryRun {
|
|
system.CurrentSystem = &platform.MockSystem{}
|
|
fmt.Println("⚠️ Running in DRY-RUN mode. No changes will be applied.")
|
|
} else {
|
|
system.CurrentSystem = &platform.LinuxKDE{}
|
|
}
|
|
},
|
|
}
|
|
|
|
func Execute() {
|
|
if err := RootCmd.Execute(); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
cobra.OnInitialize(initConfig)
|
|
// Allow passing a specific config file
|
|
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/panic-cli/config.yaml)")
|
|
RootCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "d", false, "Enable dry-run mode (no side effects)")
|
|
}
|
|
|
|
func initConfig() {
|
|
if cfgFile != "" {
|
|
viper.SetConfigFile(cfgFile)
|
|
} else {
|
|
home, err := os.UserHomeDir()
|
|
cobra.CheckErr(err)
|
|
|
|
viper.AddConfigPath(home)
|
|
viper.SetConfigType("yaml")
|
|
viper.SetConfigName(".panic-cli")
|
|
}
|
|
|
|
viper.AutomaticEnv()
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
fmt.Println("DEBUG: No config file found or read error:", err)
|
|
}
|
|
err := viper.Unmarshal(&config.AppConfig)
|
|
if err != nil {
|
|
fmt.Printf("Unable to decode into struct, %v", err)
|
|
}
|
|
}
|