mirror of
https://github.com/silicoflare/envy.git
synced 2026-05-26 11:49:52 +05:30
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
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, err := utils.GetKey(envy, "envy.project")
|
|
utils.StopIfErr(err)
|
|
|
|
pinned, err := utils.GetKey(envy, "envy.env")
|
|
utils.StopIfErr(err)
|
|
|
|
current, err := utils.GetKey(envy, "envy.current")
|
|
utils.StopIfErr(err)
|
|
|
|
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"))
|
|
currentStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#0F0"))
|
|
|
|
for _, en := range envs {
|
|
extra := ""
|
|
if en.Name == pinned {
|
|
extra += pinStyle.Render("[+]")
|
|
}
|
|
if en.Name == current {
|
|
extra += currentStyle.Render("[*]")
|
|
}
|
|
fmt.Printf(" • %s %s\n", en.Name, extra)
|
|
}
|
|
},
|
|
}
|
|
|
|
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")
|
|
}
|