feat: integrate flow-cli into Aliyun CLI#1380
Conversation
Mirror esa-cli: npm-install @flow-step/flow-cli into a local prefix, forward credentials/region, and proxy subcommands. Default registry is npmmirror per Flow-CLI docs. Compatible additive root command. 关联 Aone: 84323751
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1380 +/- ##
=======================================
Coverage 84.72% 84.72%
=======================================
Files 68 68
Lines 8869 8870 +1
=======================================
+ Hits 7514 7515 +1
Misses 915 915
Partials 440 440 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Avoid wrapping exec.ExitError so aliyun flow-cli keeps the child exit code and does not print an extra ERROR line over the tool's own output.
|
@AllyW review |
There was a problem hiding this comment.
Pull request overview
This PR integrates a new aliyun flow-cli extension command into Aliyun CLI, following the existing “CLI proxy + auto-install” pattern (similar to esa-cli). It installs/proxies @flow-step/flow-cli, forwards Aliyun profile-derived credentials/region to the subprocess, and attempts to preserve the child process’s exit code behavior.
Changes:
- Register a new
flow-cliroot subcommand in the main CLI entrypoint. - Add a new
cliext/flowcliextension that manages Node/npm detection, prefix installation, env propagation, and subprocess execution/exit-code handling. - Add unit tests covering command metadata, flag stripping, env preparation, version-check TTL, and exit-code propagation behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| main/main.go | Wires flow-cli into the root command’s subcommand list. |
| cliext/flowcli/main.go | Defines the aliyun flow-cli command wrapper (help behavior + exit code propagation path). |
| cliext/flowcli/flowcli.go | Implements install/proxy logic: runtime detection, npm prefix install/update, flag folding/stripping, env forwarding, and subprocess execution. |
| cliext/flowcli/main_test.go | Tests command metadata and the “suppress framework error output when child exits non-zero” path. |
| cliext/flowcli/flowcli_test.go | Tests core helper behavior (paths, node/npm detection, flag stripping, env injection, TTL cache, and exit error type). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err := c.EnsureNpmAvailable(); err != nil { | ||
| return err | ||
| } |
| func (c *Context) EnsurePrefixAndPackage() error { | ||
| if os.Getenv("ALIBABA_CLOUD_FLOW_CLI_EXEC_PATH") != "" { | ||
| return nil | ||
| } |
| a := args[i] | ||
| if !strings.HasPrefix(a, "--") { | ||
| continue | ||
| } | ||
| var name, value string | ||
| var hasValue bool | ||
| if idx := strings.Index(a, "="); idx > 0 { | ||
| name = a[2:idx] | ||
| value = a[idx+1:] | ||
| hasValue = true | ||
| } else { | ||
| name = a[2:] | ||
| } | ||
| f := flags.Get(name) | ||
| if f == nil || f.Category != "config" { | ||
| continue | ||
| } |
Address review feedback: - Skip the npm requirement when ALIBABA_CLOUD_FLOW_CLI_EXEC_PATH points at an existing binary, so the local-binary escape hatch works without npm. - Validate the EXEC_PATH override up front and fail with a clear message instead of a cryptic exec error later. - Fold config shorthands (e.g. -p profile, -e endpoint) into the parsed flags so credential/region overrides are honored under KeepArgs.
Summary
aliyun flow-cliroot command that installs and proxies@flow-step/flow-cli(same pattern as esa-cli)~/.aliyun/flow-cli-prefixwith npmmirror as default registry; forward profile credentials/regioncli.Exitso child exit codes and output are not overwritten by the CLI framework