Move env command to top level
This commit is contained in:
parent
af9bf6190e
commit
93b3a95f33
@ -1,50 +1,41 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/Jaculabilis/intake/core"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var sourceEnvCmd = &cobra.Command{
|
||||
var envCmd = &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
|
||||
--env 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.
|
||||
--env KEY= will delete the environment variable from the source.
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
sourceEnv(stringArg(cmd, "source"), stringArrayArg(cmd, "set"))
|
||||
sourceEnv(stringArg(cmd, "source"), stringArrayArg(cmd, "env"))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
sourceCmd.AddCommand(sourceEnvCmd)
|
||||
rootCmd.AddCommand(envCmd)
|
||||
|
||||
sourceEnvCmd.Flags().StringP("source", "s", "", "Source to edit")
|
||||
sourceEnvCmd.MarkFlagRequired("source")
|
||||
envCmd.Flags().StringP("source", "s", "", "Source to edit")
|
||||
envCmd.MarkFlagRequired("source")
|
||||
|
||||
sourceEnvCmd.Flags().StringArray("set", nil, "Set or modify environment variable")
|
||||
envCmd.Flags().StringArray("env", 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)
|
||||
}
|
||||
log.Fatal("error: no --env specified")
|
||||
}
|
||||
|
||||
if err := core.SetEnvs(db, source, env); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user