Skip to content

Commit dd7c94b

Browse files
committed
Improve the user experience by checking function existence before prompting for deployment configuration
Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
1 parent 11f389b commit dd7c94b

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

cmd/deploy.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,20 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
241241
cfg deployConfig
242242
f fn.Function
243243
)
244-
if cfg, err = newDeployConfig(cmd).Prompt(); err != nil {
245-
return
246-
}
247-
if err = cfg.Validate(cmd); err != nil {
248-
return
249-
}
244+
245+
// Initialize config first
246+
cfg = newDeployConfig(cmd)
247+
248+
// Create function object to check if initialized
250249
if f, err = fn.NewFunction(cfg.Path); err != nil {
251250
return
252251
}
253-
if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg
254-
return
255-
}
256-
cmd.SetContext(cfg.WithValues(cmd.Context())) // Some optional settings are passed via context
257-
252+
253+
// Check if function exists BEFORE prompting for config
258254
if !f.Initialized() {
259255
if !cfg.Remote || f.Build.Git.URL == "" {
260256
// Only error if this is not a fully remote build
261-
return fn.NewErrNotInitialized(f.Root)
257+
return fmt.Errorf("no function found in current directory.\nYou need to be inside a function directory to deploy it.\n\nTry this:\n func create --language go myfunction Create a new function\n cd myfunction Go into the function directory\n func deploy --registry <registry> Deploy to the cloud\n\nOr if you have an existing function:\n cd path/to/your/function Go to your function directory\n func deploy --registry <registry> Deploy the function\n\nFor more detailed deployment options, run 'func deploy --help'.")
262258
} else {
263259
// TODO: this case is not supported because the pipeline
264260
// implementation requires the function's name, which is in the
@@ -267,6 +263,18 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
267263
return errors.New("please ensure the function's source is also available locally")
268264
}
269265
}
266+
267+
// Now that we know function exists, proceed with prompting
268+
if cfg, err = cfg.Prompt(); err != nil {
269+
return
270+
}
271+
if err = cfg.Validate(cmd); err != nil {
272+
return
273+
}
274+
if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg
275+
return
276+
}
277+
cmd.SetContext(cfg.WithValues(cmd.Context())) // Some optional settings are passed via context
270278

271279
changingNamespace := func(f fn.Function) bool {
272280
// We're changing namespace if:

0 commit comments

Comments
 (0)