mirror of https://github.com/knative/func.git
fix: func delete with explicity name as argument (#323) with strict validation
This commit is contained in:
parent
87fd7babf1
commit
8ab0ba243a
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue