refactor: seperate files, function and structs into seperate packages

This commit is contained in:
Patryk Hegenberg 2025-01-18 14:34:16 +01:00
parent 7f951585c8
commit 5b7775f33e
37 changed files with 547 additions and 677 deletions

58
cmd/cmd.go Normal file
View file

@ -0,0 +1,58 @@
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",
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)")
packageCmd.AddCommand(addCmd, deleteCmd, showCmd, enableCmd)
RootCmd.AddCommand(packageCmd, searchCmd, installCmd, removeCmd)
}
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)
}
}