61 lines
2.4 KiB
Go
61 lines
2.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"system_setup_tool/tui"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var RootCmd = &cobra.Command{
|
|
Use: "system_setup_tool",
|
|
Short: "Installs packages based on TOML configuration",
|
|
Version: "0.4.0",
|
|
Run: tui.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")
|
|
|
|
installCmd.Flags().StringP("manager", "m", "os", "The package manager you want to install a package with. (Options: os|homebrew|pipx|flatpak|cargo)")
|
|
|
|
removeCmd.Flags().StringP("manager", "m", "os", "The package manager you want to remove a package with. (Options: os|homebrew|pipx|flatpak|cargo)")
|
|
|
|
searchCmd.Flags().StringP("manager", "m", "", "The package manager you want to search a package with. (Options: os|homebrew|flatpak)")
|
|
|
|
updateCmd.Flags().StringP("manager", "m", "os", "The package manager you want to update packages with. (Options: os|homebrew|pipx|flatpak)")
|
|
|
|
packageCmd.AddCommand(addCmd, deleteCmd, showCmd, enableCmd)
|
|
RootCmd.AddCommand(packageCmd, searchCmd, installCmd, removeCmd, updateCmd, updateAllCmd)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|