35 lines
747 B
Go
35 lines
747 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "package-installer",
|
|
Short: "Installiert Pakete basierend auf TOML-Konfiguration",
|
|
Run: run,
|
|
}
|
|
|
|
func init() {
|
|
cobra.OnInitialize(initConfig)
|
|
rootCmd.PersistentFlags().StringP("config", "c", "", "Pfad zur Konfigurationsdatei")
|
|
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
|
|
}
|
|
|
|
func initConfig() {
|
|
if cfgFile := viper.GetString("config"); cfgFile != "" {
|
|
viper.SetConfigFile(cfgFile)
|
|
} else {
|
|
viper.SetConfigName("config")
|
|
viper.AddConfigPath(".")
|
|
}
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
fmt.Println("Fehler beim Lesen der Konfigurationsdatei:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|