Skip to content

Commit 8ab0ba2

Browse files
committed
fix: func delete with explicity name as argument (#323) with strict validation
1 parent 87fd7ba commit 8ab0ba2

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

cmd/delete.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,31 @@ kn func delete -n apps myfunc
4242
RunE: runDelete,
4343
}
4444

45+
4546
func runDelete(cmd *cobra.Command, args []string) (err error) {
4647
config := newDeleteConfig(args).Prompt()
47-
48-
function, err := fn.NewFunction(config.Path)
49-
if err != nil {
50-
return
51-
}
52-
53-
// Check if the Function has been initialized
54-
if !function.Initialized() {
55-
return fmt.Errorf("the given path '%v' does not contain an initialized function", config.Path)
48+
49+
var function fn.Function
50+
51+
// Initialize func with explicit name (when provided)
52+
if len(args) > 0 && args[0] != "" {
53+
pathChanged := cmd.Flags().Changed("path")
54+
if pathChanged {
55+
return fmt.Errorf("Only one of --path and [NAME] should be provided")
56+
}
57+
function = fn.Function{
58+
Name: args[0],
59+
}
60+
} else {
61+
function, err = fn.NewFunction(config.Path)
62+
if err != nil {
63+
return
64+
}
65+
66+
// Check if the Function has been initialized
67+
if !function.Initialized() {
68+
return fmt.Errorf("the given path '%v' does not contain an initialized function", config.Path)
69+
}
5670
}
5771

5872
ns := config.Namespace

0 commit comments

Comments
 (0)