intake/cmd/env.go
2025-03-07 11:19:36 -08:00

46 lines
1023 B
Go

package cmd
import (
"log"
"github.com/Jaculabilis/intake/core"
"github.com/spf13/cobra"
)
var envCmd = &cobra.Command{
Use: "env",
GroupID: sourceGroup.ID,
Short: "Manage source environment variables",
Long: `Add, edit, list, or delete environment variables.
--env KEY=VALUE will add or edit an environment variable to be set in all
action executions.
--env KEY= will delete the environment variable from the source.
`,
Run: func(cmd *cobra.Command, args []string) {
sourceEnv(stringArg(cmd, "source"), stringArrayArg(cmd, "env"))
},
}
func init() {
rootCmd.AddCommand(envCmd)
envCmd.Flags().StringP("source", "s", "", "Source to edit")
envCmd.MarkFlagRequired("source")
envCmd.Flags().StringArray("env", nil, "Set or modify environment variable")
}
func sourceEnv(source string, env []string) {
db := openAndMigrateDb()
if len(env) == 0 {
log.Fatal("error: no --env specified")
}
if err := core.SetEnvs(db, source, env); err != nil {
log.Fatalf("failed to set envs: %v", err)
}
}