Repository navigation
refactor(cli): split cli.py into a commands package and share helpers - #384
Draft
digitalresistor wants to merge 5 commits into
Draft
digitalresistor wants to merge 5 commits into
digitalresistor wants to merge 5 commits into
Conversation
preflight/checks.py reports the pre-created Stage 0 resources through
one precreate_status function and resolves role holders through a pure
holder_member function, and repo.py reads locals, resources, modules and
variables through four small HCL helpers instead of repeated traversals.
* Every check keeps its results, messages and order, so preflight
output does not change.
The render steps move from private helpers in cli.py into the
render/pipeline.py module, which returns warnings, rows and diff text
instead of printing, and render/writer.py now owns the generated-file
marker, is_generated and write_owned that the phase and import files
carried as duplicated code.
* No command changes behavior; the next commits wire stellar render to
the new module, which runs the same steps in the same order.
config/answers.py gains update, which changes an answers file through a
callback, keeps comments and key order, validates the result and skips
the save when nothing changed. The new org_policies.py module holds the
organization policy scan and save that stellar imports scan performs.
* Commands do not change yet; a later commit wires stellar imports
scan to the new module without changing its output.
cli.py keeps the Typer apps, the version callback and a registration
table, and one module per command lives under commands/, with the
shared options, exit codes, the ExitOn context manager, the environment
loaders and the prompter, console and now factories in
commands/common.py.
* Every command prints the same text, exits with the same codes and
shows the same --help output; the tests only change their monkeypatch
targets.
conftest.py gains the isolated_home, cli_runner, fake_cloud and
fake_tools fixtures and helpers.py the init_env, invoke and
terraform_init helpers, so tests/test_cli.py splits into one module per
command and the new modules reuse the same setup.
* Every test of the former module survives by name, and new tests
cover ExitOn, load_env, the factories and the exact env list and env
show output.
12 of 19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request splits
cli/src/stellar_engine/cli.pyinto acommands/package and moves the steps that the guided deploy reuses into library modules, with no change in behavior. It is the R13 refactor from the CLI tracking issue, and thefeat(cli): guided deploypull request builds on it.cli.pymodule keeps the Typer apps, the version callback, the exit code docstring and a registration table that fixes thestellar --helporder.commands/init.py,commands/env.py,commands/imports.py,commands/render.pyandcommands/preflight.pymodules hold one command each as plain functions and never importcli.commands/common.pymodule holds the shared options, thefailandwarnhelpers, theExitOncontext manager that replaces the repeated try and except blocks, the session and environment loaders, and theprompter,consoleandnowfactories that tests replace.render/pipeline.pymodule holds the render steps as functions that return warnings, summary rows and diff text instead of printing, so a later command can render a stage and read the result.render/writer.pymodule owns theMARKERline,is_generatedandwrite_owned, which the import file and the Stage 0 phase file carried as duplicated code.config/answers.pymodule gainsupdate, which changes an answers file through a callback, keeps its comments and key order, validates the result and skips the save when nothing changed.org_policies.pymodule wraps the organization policy scan and the save thatstellar imports scanperforms.preflight/checks.pymodule reports the pre-created Stage 0 resources through oneprecreate_statusfunction and resolves role holders through one pureholder_memberfunction instead of two copies of each.repo.pymodule reads locals, resources, modules and variables through four small HCL helpers instead of repeated traversals.isolated_home,cli_runner,fake_cloudandfake_toolsfixtures and theinit_env,invokeandterraform_inithelpers, andtests/test_cli.pysplits into one module per command. Every test of the former module survives by name, and new tests coverExitOn,load_env,answers.update,org_policies, the render pipeline,holder_member, and the exactenv listandenv showoutput.Every command prints the same text, exits with the same codes and shows the same
--helpoutput as before. Thecli/README.mdfile stays unchanged because no command, flag or output changes.Part of #306. No separate issue exists for the split.
Type of Change
This is a refactor with no behavior change, so none of the boxes applies.
Deployment & Compliance Impact
Checklist
Code Quality & Reusability
modules/orfast/stages-aw/can be leveraged for this change.docs/naming-convention.md.Documentation
README.mdof the modified module or blueprint. The README needs no update because the commands, flags, outputs and exit codes stay the same.Security
Testing
Testing Performed
uv run pytestfrom thecli/directory passes 962 tests, with the Terraform marked tests running against a local Terraform binary and all 14 syrupy snapshots matching.uv run ruff format --check,uv run ruff checkanduv run pyrightfrom thecli/directory report no findings.python3 tools/check_boilerplate.py cliandpytestfrom the repository root pass.stellar,stellar env,stellar importsand of theinit,env list,env use,env show,imports scan,renderandpreflightcommands was captured onmainand on this branch under the sameCOLUMNS,TERMandNO_COLORsettings and compared byte for byte; every file is identical.init,render,render --diff,render --force,envandimports scanonmainand on this branch in temporary homes and compared stdout, stderr and exit codes; every scenario is identical.tests/test_cli.pywere compared with the split modules; all 66 survive.