envoid/cmd/rm.go
Sagi Dayan 7dc10b7062
Some checks failed
ci/ci / Check for spelling errors (pull_request) Successful in 22s
ci/ci / GonalgCI lint (pull_request) Failing after 1m13s
ci/ci / Make sure build does not fail (pull_request) Has been skipped
ci/ci / notify-fail (pull_request) Successful in 13s
Added lint to the CI. formatted all code accordingly
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
2024-12-16 22:41:22 +02:00

63 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"git.dayanhub.com/sagi/envoid/internal/datastore"
"git.dayanhub.com/sagi/envoid/internal/errors"
"git.dayanhub.com/sagi/envoid/internal/types"
"github.com/spf13/cobra"
)
type rmCmdFlags struct {
envName *string
}
var rmFlags = rmCmdFlags{}
var rmCmd = &cobra.Command{
Use: "rm <key>",
Short: "removes a variable from environment(s)",
Long: "",
RunE: func(cmd *cobra.Command, args []string) error {
err := initProject()
if err != nil {
return err
}
if project.IsEmpty() {
return errors.NewProjectEmptyError(project.Name)
}
if len(args) != 1 {
return errors.NewInvalidCommandError("expected 1 args. <key>")
}
key := args[0]
ds, err := datastore.NewDataStore()
if err != nil {
fmt.Printf("Error: %e", err)
}
defer ds.Close()
envs := project.Environments
if len(*rmFlags.envName) != 0 {
e, err := project.GetEnv(*rmFlags.envName)
if err != nil {
return err
}
envs = []*types.Environment{e}
}
ds.RemoveVar(key, envs)
return nil
},
}
func init() {
rmFlags.envName = rmCmd.Flags().StringP("environment", "e", "", "environments name")
err := rmCmd.RegisterFlagCompletionFunc("environment", validEnvironmentNamesComplete)
if err != nil {
panic(err)
}
}