11package cmd
22
33import (
4+ "errors"
45 "fmt"
56
67 "github.com/AlecAivazis/survey/v2"
@@ -36,7 +37,28 @@ No local files are deleted.
3637 PreRunE : bindEnv ("path" , "confirm" , "all" , "namespace" , "verbose" ),
3738 SilenceUsage : true , // no usage dump on error
3839 RunE : func (cmd * cobra.Command , args []string ) error {
39- return runDelete (cmd , args , newClient )
40+ // Layer 2: Catch technical errors and provide CLI-specific user-friendly messages
41+ err := runDelete (cmd , args , newClient )
42+ if err != nil && errors .Is (err , fn .ErrNameRequiredForDelete ) {
43+ return fmt .Errorf (`%v
44+
45+ You can delete functions in two ways:
46+
47+ 1. By name :
48+ func delete myfunction Delete function by name
49+ func delete myfunction --namespace apps Delete from specific namespace
50+
51+ 2. By path :
52+ func delete --path /path/to/function Delete function at specific path
53+
54+ Examples:
55+ func delete myfunction Delete 'myfunction' from cluster
56+ func delete myfunction --namespace prod Delete from 'prod' namespace
57+ func delete --path ./myfunction Delete function at path
58+
59+ For more options, run 'func delete --help'` , err )
60+ }
61+ return err
4062 },
4163 }
4264
@@ -61,6 +83,19 @@ func runDelete(cmd *cobra.Command, args []string, newClient ClientFactory) (err
6183 if err != nil {
6284 return
6385 }
86+
87+ // If no name provided, check if function exists BEFORE prompting or connecting to cluster
88+ if cfg .Name == "" {
89+ f , err := fn .NewFunction (cfg .Path )
90+ if err != nil {
91+ return err
92+ }
93+ if ! f .Initialized () {
94+ // Return technical error (Layer 1) - will be caught and enhanced by CLI
95+ return fn .ErrNameRequiredForDelete
96+ }
97+ }
98+
6499 if cfg , err = cfg .Prompt (); err != nil {
65100 return
66101 }
0 commit comments