feat: add noninteractive path to func config envs remove (#2879)

This commit is contained in:
Luke Kingland 2025-06-27 16:37:07 +09:00 committed by GitHub
parent c990659a11
commit ffd997c448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 5 deletions

View File

@ -48,7 +48,7 @@ the current directory or from the directory specified with --path.
cmd.Flags().StringP("output", "o", "human", "Output format (human|json) ($FUNC_OUTPUT)")
configEnvsAddCmd := NewConfigEnvsAddCmd(loadSaver)
configEnvsRemoveCmd := NewConfigEnvsRemoveCmd()
configEnvsRemoveCmd := NewConfigEnvsRemoveCmd(loadSaver)
addPathFlag(cmd)
addPathFlag(configEnvsAddCmd)
@ -139,8 +139,8 @@ set environment variable from a secret
return cmd
}
func NewConfigEnvsRemoveCmd() *cobra.Command {
return &cobra.Command{
func NewConfigEnvsRemoveCmd(loadSaver functionLoaderSaver) *cobra.Command {
cmd := &cobra.Command{
Use: "remove",
Short: "Remove environment variable from the function configuration",
Long: `Remove environment variable from the function configuration
@ -150,17 +150,40 @@ in the current directory or from the directory specified with --path.
`,
Aliases: []string{"rm"},
SuggestFor: []string{"del", "delete", "rmeove"},
PreRunE: bindEnv("path", "verbose"),
PreRunE: bindEnv("path", "name", "verbose"),
RunE: func(cmd *cobra.Command, args []string) (err error) {
function, err := initConfigCommand(defaultLoaderSaver)
function, err := initConfigCommand(loadSaver)
if err != nil {
return
}
var name string
if cmd.Flags().Changed("name") {
s, e := cmd.Flags().GetString("name")
if e != nil {
return e
}
name = s
}
if name != "" {
envs := []fn.Env{}
for _, v := range function.Run.Envs {
if *v.Name != name {
envs = append(envs, v)
}
}
function.Run.Envs = envs
return loadSaver.Save(function)
}
return runRemoveEnvsPrompt(function)
},
}
cmd.Flags().StringP("name", "", "", "Name of the environment variable.")
return cmd
}
func listEnvs(f fn.Function, w io.Writer, outputFormat Format) error {

View File

@ -18,6 +18,7 @@ func config envs remove
```
-h, --help help for remove
--name string Name of the environment variable.
-p, --path string Path to the function. Default is current directory ($FUNC_PATH)
-v, --verbose Print verbose logs ($FUNC_VERBOSE)
```