54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/Jaculabilis/intake/core"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var sourceEnvCmd = &cobra.Command{
|
|
Use: "env",
|
|
Short: "Manage source environment variables",
|
|
Long: `Add, edit, list, or delete environment variables.
|
|
|
|
When --set is not specified, list the environment for the source.
|
|
|
|
--set KEY=VALUE will add or edit an environment variable to be set in all
|
|
action executions.
|
|
|
|
--set KEY= will delete the environment variable from the source.
|
|
`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
sourceEnv(stringArg(cmd, "source"), stringArrayArg(cmd, "set"))
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
sourceCmd.AddCommand(sourceEnvCmd)
|
|
|
|
sourceEnvCmd.Flags().StringP("source", "s", "", "Source to edit")
|
|
sourceEnvCmd.MarkFlagRequired("source")
|
|
|
|
sourceEnvCmd.Flags().StringArray("set", nil, "Set or modify environment variable")
|
|
}
|
|
|
|
func sourceEnv(source string, env []string) {
|
|
db := openAndMigrateDb()
|
|
|
|
if len(env) == 0 {
|
|
envs, err := core.GetEnvs(db, source)
|
|
if err != nil {
|
|
log.Fatalf("failed to get envs: %v", err)
|
|
}
|
|
for _, env := range envs {
|
|
fmt.Println(env)
|
|
}
|
|
}
|
|
|
|
if err := core.SetEnvs(db, source, env); err != nil {
|
|
log.Fatalf("failed to set envs: %v", err)
|
|
}
|
|
}
|