Skip to content

Commit 7353e13

Browse files
authored
Improve func deploy UX by checking function existence before prompting (#3042)
* Improve the user experience by checking function existence before prompting for deployment configuration Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com> * Improve the description formatting using backticks Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com> * fix the linter issues Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com> * update component versions failing ci test Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com> --------- Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
1 parent 109a5be commit 7353e13

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

cmd/deploy.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,32 @@ 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
257252

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.
258+
You need to be inside a function directory to deploy it.
259+
260+
Try this:
261+
func create --language go myfunction Create a new function
262+
cd myfunction Go into the function directory
263+
func deploy --registry <registry> Deploy to the cloud
264+
265+
Or if you have an existing function:
266+
cd path/to/your/function Go to your function directory
267+
func deploy --registry <registry> Deploy the function
268+
269+
For more detailed deployment options, run 'func deploy --help'`)
262270
} else {
263271
// TODO: this case is not supported because the pipeline
264272
// implementation requires the function's name, which is in the
@@ -268,6 +276,18 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
268276
}
269277
}
270278

279+
// Now that we know function exists, proceed with prompting
280+
if cfg, err = cfg.Prompt(); err != nil {
281+
return
282+
}
283+
if err = cfg.Validate(cmd); err != nil {
284+
return
285+
}
286+
if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg
287+
return
288+
}
289+
cmd.SetContext(cfg.WithValues(cmd.Context())) // Some optional settings are passed via context
290+
271291
changingNamespace := func(f fn.Function) bool {
272292
// We're changing namespace if:
273293
return f.Deploy.Namespace != "" && // it's already deployed

0 commit comments

Comments
 (0)