package cmdEnv

import (
	"fmt"
	"kode-starter/config"
	"os"
	"strings"

	"github.com/spf13/cobra"
)

var EnvCmd = &cobra.Command{
	Use:   "env",
	Short: "manage environment variables",
	Long:  `A simple CLI option to manage environment variables`,
	Run: func(cmd *cobra.Command, args []string) {

		config.SetInformations(cmd, args)

		// if option --env or -e is set then print environment variables
		if envVariablesFlag {
			printEnvVariables()
		}

	},
}

func printEnvVariables() {
	fmt.Println("Environment variables")
	fmt.Println("---------------------")

	// loop over all environment variables
	for _, e := range os.Environ() {
		// split key and value
		pair := strings.Split(e, "=")
		fmt.Println(pair[0])
	}
}
