-
Notifications
You must be signed in to change notification settings - Fork 16
fix: infer template from --marketplace-code to prevent silent deploy failure #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,13 +43,31 @@ func NewCmdDeploy(f *cmdutil.Factory) *cobra.Command { | |
| } | ||
|
|
||
| func runDeploy(f *cmdutil.Factory, opts *Options) error { | ||
| // Infer template from flags when not explicitly set | ||
| inferTemplate(opts) | ||
|
|
||
| if f.Interactive { | ||
| return runDeployInteractive(f, opts) | ||
| } else { | ||
| return runDeployNonInteractive(f, opts) | ||
| } | ||
| } | ||
|
|
||
| // inferTemplate automatically sets the template based on other provided flags. | ||
| // If --marketplace-code is provided, the user clearly wants a PREBUILT deployment. | ||
| // If --repo-id is provided, the user clearly wants a GIT deployment. | ||
| func inferTemplate(opts *Options) { | ||
| if opts.template != "" { | ||
| return | ||
| } | ||
|
|
||
| if opts.marketplaceCode != "" { | ||
| opts.template = "PREBUILT" | ||
| } else if opts.repoID != 0 { | ||
| opts.template = "GIT" | ||
| } | ||
| } | ||
|
|
||
| func runDeployNonInteractive(f *cmdutil.Factory, opts *Options) error { | ||
| if opts.projectID == "" { | ||
| return fmt.Errorf("--project-id is required") | ||
|
|
@@ -231,23 +249,30 @@ func runDeployInteractive(f *cmdutil.Factory, opts *Options) error { | |
|
|
||
| func paramCheck(opts *Options) error { | ||
| if opts.template == "" { | ||
| return fmt.Errorf("please specify service template with --template") | ||
| return fmt.Errorf("please specify service template with --template (PREBUILT or GIT)\n" + | ||
| " Example: zeabur service deploy --template PREBUILT --marketplace-code postgresql --project-id <id>\n" + | ||
| " Example: zeabur service deploy --template GIT --repo-id <id> --branch-name main --project-id <id>") | ||
| } | ||
|
|
||
| if strings.ToUpper(opts.template) != "PREBUILT" && strings.ToUpper(opts.template) != "GIT" { | ||
| return fmt.Errorf("unsupported service template %s, only support PREBUILT and GIT", opts.template) | ||
| template := strings.ToUpper(opts.template) | ||
|
|
||
| if template != "PREBUILT" && template != "GIT" { | ||
| return fmt.Errorf("unsupported service template %q, only PREBUILT and GIT are supported", opts.template) | ||
| } | ||
|
|
||
| if opts.template == "PREBUILT" && opts.marketplaceCode == "" { | ||
| return fmt.Errorf("please specify marketplace item code with --marketplace-code") | ||
| if template == "PREBUILT" && opts.marketplaceCode == "" { | ||
| return fmt.Errorf("--marketplace-code is required for PREBUILT template\n" + | ||
| " Example: zeabur service deploy --template PREBUILT --marketplace-code postgresql --project-id <id>") | ||
| } | ||
|
Comment on lines
+263
to
266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unknown This only checks presence, not validity. For invalid codes, users still depend on backend failure paths instead of getting the expected list of valid marketplace codes in CLI output. 🤖 Prompt for AI Agents |
||
|
|
||
| if opts.template == "GIT" && opts.repoID == 0 { | ||
| return fmt.Errorf("please specify git repository ID with --repo-id") | ||
| if template == "GIT" && opts.repoID == 0 { | ||
| return fmt.Errorf("--repo-id is required for GIT template\n" + | ||
| " Example: zeabur service deploy --template GIT --repo-id <id> --branch-name main --project-id <id>") | ||
| } | ||
|
|
||
| if opts.template == "GIT" && opts.branchName == "" { | ||
| return fmt.Errorf("please specify git branch name with --branch-name") | ||
| if template == "GIT" && opts.branchName == "" { | ||
| return fmt.Errorf("--branch-name is required for GIT template\n" + | ||
| " Example: zeabur service deploy --template GIT --repo-id <id> --branch-name main --project-id <id>") | ||
| } | ||
|
|
||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--repo-idinference still conflicts with interactive flag precedence.When this infers
GITfrom--repo-id, the interactiveGITflow still prompts repository selection and can overwrite the provided repo. That makes the flag non-authoritative in interactive mode.As per coding guidelines: "Commands should support both interactive and non-interactive modes; if a flag is provided, skip the interactive prompt."
🤖 Prompt for AI Agents