/* Copyright © 2025 NAME HERE */ package cmd import ( "envy/cmd/utils" "fmt" "os" "path" "github.com/spf13/cobra" ) // fetchCmd represents the fetch command var fetchCmd = &cobra.Command{ Use: "fetch", Short: "Automatically get the pinned environment for this project", Run: func(cmd *cobra.Command, args []string) { envy, err := utils.GetEnvy() utils.StopIfErr(err) project, err := utils.GetKey(envy, "envy.project") utils.StopIfErr(err) pinned, err := utils.GetKey(envy, "envy.env") utils.StopIfErr(err) dbProject, err := utils.GetProject(project) utils.StopIfErr(err) dbEnv, err := utils.GetEnvironment(dbProject.ID, pinned) utils.StopIfErr(err) cwd, err := os.Getwd() utils.StopIfErr(err) os.WriteFile(path.Join(cwd, ".env"), []byte(dbEnv.Data), 0755) envy.Set("envy.current", pinned) err = utils.WriteEnvy(envy) utils.StopIfErr(err) fmt.Printf("Fetched environment %s for project %s.\n", pinned, project) }, } func init() { rootCmd.AddCommand(fetchCmd) // Here you will define your flags and configuration settings. // Cobra supports Persistent Flags which will work for this command // and all subcommands, e.g.: // fetchCmd.PersistentFlags().String("foo", "", "A help for foo") // Cobra supports local flags which will only run when this command // is called directly, e.g.: // fetchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") }