system_setup_tool/cmd.go
Patryk Hegenberg c9bf9c9a6f feature(cli): add packages command and various subcommands
add commands to handle package management
add -> adds packages
delete -> deletes packages
show -> shows config sorted by package_managers
2025-01-16 22:27:29 +01:00

51 lines
1.7 KiB
Go

package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var rootCmd = &cobra.Command{
Use: "system_setup_tool",
Short: "Installs packages based on TOML configuration",
Run: run,
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringP("config", "c", "", "Path to the configuration file")
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
addCmd.Flags().StringP("name", "n", "", "The name of the package you want to add")
addCmd.Flags().StringP("manager", "m", "", "The package manager you want to add the package to (homebrew|cargo|flatpak|pipx|go)")
addCmd.Flags().Bool("system", false, "Add as a system package")
addCmd.Flags().Bool("headless", false, "Add as a headless system package (only used with --system)")
deleteCmd.Flags().StringP("name", "n", "", "The name of the package you want to delete")
deleteCmd.Flags().StringP("manager", "m", "", "The package manager you want to delete the package from (homebrew|cargo|flatpak|pipx|go)")
deleteCmd.Flags().Bool("system", false, "Delete from system packages")
deleteCmd.Flags().Bool("headless", false, "Delete from headless system packages (only used with --system)")
enableCmd.Flags().Bool("value", true, "Set to true to enable, false to disable")
packageCmd.AddCommand(addCmd, deleteCmd, showCmd, enableCmd)
rootCmd.AddCommand(packageCmd)
}
func initConfig() {
if cfgFile := viper.GetString("config"); cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
viper.SetConfigName("config")
viper.SetConfigType("toml")
viper.AddConfigPath(".")
}
if err := viper.ReadInConfig(); err != nil {
fmt.Println("Error reading configuration file:", err)
os.Exit(1)
}
}