fix: func delete with explicity name as argument (#323) with strict validation

This commit is contained in:
Jefferson Ramos 2021-04-30 10:23:52 -03:00
parent 87fd7babf1
commit 8ab0ba243a
1 changed files with 21 additions and 7 deletions

View File

@ -42,17 +42,31 @@ kn func delete -n apps myfunc
RunE: runDelete, RunE: runDelete,
} }
func runDelete(cmd *cobra.Command, args []string) (err error) { func runDelete(cmd *cobra.Command, args []string) (err error) {
config := newDeleteConfig(args).Prompt() config := newDeleteConfig(args).Prompt()
var function fn.Function
function, err := fn.NewFunction(config.Path) // Initialize func with explicit name (when provided)
if err != nil { if len(args) > 0 && args[0] != "" {
return pathChanged := cmd.Flags().Changed("path")
} if pathChanged {
return fmt.Errorf("Only one of --path and [NAME] should be provided")
}
function = fn.Function{
Name: args[0],
}
} else {
function, err = fn.NewFunction(config.Path)
if err != nil {
return
}
// Check if the Function has been initialized // Check if the Function has been initialized
if !function.Initialized() { if !function.Initialized() {
return fmt.Errorf("the given path '%v' does not contain an initialized function", config.Path) return fmt.Errorf("the given path '%v' does not contain an initialized function", config.Path)
}
} }
ns := config.Namespace ns := config.Namespace