package cmd import ( "envy/cmd/utils" "fmt" "github.com/charmbracelet/lipgloss" "github.com/spf13/cobra" ) // listCmd represents the list command var listCmd = &cobra.Command{ Use: "list", Short: "List all the environments in the current project", Run: func(cmd *cobra.Command, args []string) { envy, err := utils.GetEnvy() if err != nil { utils.ErrPrint(err.Error()) return } project := envy.Get("envy.project").(string) pinned := envy.Get("envy.env").(string) if project == "" { utils.ErrPrint("Project name is empty. envy.toml file might have been modified.") return } if pinned == "" { utils.ErrPrint("Pinned environment is empty. envy.toml file might have been modified.") return } dbProject, err := utils.GetProject(project) if err != nil { utils.ErrPrint(err.Error()) return } envs, err := utils.GetEnvironments(dbProject.ID) if err != nil { utils.ErrPrint(err.Error()) return } pinStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#0FF")) for _, en := range envs { if en.Name == pinned { fmt.Println(" * " + en.Name + pinStyle.Render(" [pinned]")) } else { fmt.Println(" * " + en.Name) } } }, } func init() { rootCmd.AddCommand(listCmd) // Here you will define your flags and configuration settings. // Cobra supports Persistent Flags which will work for this command // and all subcommands, e.g.: // listCmd.PersistentFlags().String("foo", "", "A help for foo") // Cobra supports local flags which will only run when this command // is called directly, e.g.: // listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") }