mirror of
https://github.com/silicoflare/envy.git
synced 2026-05-26 19:57:59 +05:30
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"envy/cmd/utils"
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// updateCmd represents the update command
|
|
var updateCmd = &cobra.Command{
|
|
Use: "update",
|
|
Short: "Update the current environment data with the new one",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
envy, err := utils.GetEnvy()
|
|
utils.StopIfErr(err)
|
|
|
|
project, err := utils.GetKey(envy, "envy.project")
|
|
utils.StopIfErr(err)
|
|
|
|
current, err := utils.GetKey(envy, "envy.current")
|
|
utils.StopIfErr(err)
|
|
|
|
projectDb, err := utils.GetProject(project)
|
|
utils.StopIfErr(err)
|
|
|
|
currentDb, err := utils.GetEnvironment(projectDb.ID, current)
|
|
utils.StopIfErr(err)
|
|
|
|
cwd, err := os.Getwd()
|
|
utils.StopIfErr(err)
|
|
|
|
env, err := os.ReadFile(path.Join(cwd, ".env"))
|
|
utils.StopIfErr(err)
|
|
|
|
if currentDb.Data == utils.ParseEnv(string(env)) {
|
|
utils.ErrPrint("No changes found to update.")
|
|
return
|
|
}
|
|
|
|
result := utils.DB.Model(¤tDb).Update("data", utils.ParseEnv(string(env)))
|
|
utils.StopIfErr(result.Error)
|
|
|
|
fmt.Printf("Updated data for environment %s.\n", current)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(updateCmd)
|
|
}
|