/* Copyright © 2025 NAME HERE */ package cmd import ( "envy/cmd/utils" "fmt" "os" "path" "github.com/spf13/cobra" ) // initCmd represents the init command var initCmd = &cobra.Command{ Use: "init", Short: "Initialize envy on your system", Run: func(cmd *cobra.Command, args []string) { config, err := os.UserConfigDir() if err != nil { fmt.Println(utils.ErrStyle.Render("Config directory not found for your OS. Please run `envy init `.")) return } envyPath := path.Join(config, "envy") _, err = os.Stat(envyPath) if os.IsExist(err) { fmt.Println(utils.ErrStyle.Render("Config directory already exists.")) return } err = os.Mkdir(envyPath, 0755) if err != nil { fmt.Println(utils.ErrStyle.Render("Failed to create config directory:", err.Error())) } configFile, err := os.Create(path.Join(envyPath, "config.toml")) if err != nil { fmt.Println(utils.ErrStyle.Render("Failed to create config file:", err.Error())) } defer configFile.Close() _, err = os.Create(path.Join(envyPath, "envy.db")) if err != nil { fmt.Println(utils.ErrStyle.Render("Failed to create database file:", err.Error())) } utils.Migrate() configFile.Write([]byte("[config]\nmode = \"local\"\n")) fmt.Println("envy initialized on your system.") }, } func init() { rootCmd.AddCommand(initCmd) // Here you will define your flags and configuration settings. // Cobra supports Persistent Flags which will work for this command // and all subcommands, e.g.: // initCmd.PersistentFlags().String("foo", "", "A help for foo") // Cobra supports local flags which will only run when this command // is called directly, e.g.: // initCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") }