Skip to content

feat(console): add run command to invoke other registered commands#143

Closed
bedus-creation wants to merge 1 commit into
mainfrom
task/run-console-command
Closed

feat(console): add run command to invoke other registered commands#143
bedus-creation wants to merge 1 commit into
mainfrom
task/run-console-command

Conversation

@bedus-creation

Copy link
Copy Markdown
Contributor

Summary

Adds a built-in run console command to the core framework that invokes another registered console command programmatically (Laravel call-style), forwarding arguments and propagating the called command's exit code.

artisan run db:migrate
artisan run db:seed -- --force

What it does

  • New RunCommand (console/run_command.py) — a thin wrapper over Cleo's Command.call(name, args).
  • Takes a required command_name argument and an optional variadic args argument.
  • Forwarded options are passed after -- (standard Cleo option-terminator), e.g. run db:seed -- --force.
  • Returns the called command's exit code, which Cleo propagates as the process exit status.
  • Registered in AppProvider.boot() alongside provider:publish.

Implementation note

Cleo's call re-tokenizes the args string and binds it against the target command merged with the application definition, whose first positional is the command name. The name therefore leads the forwarded string so the first real argument isn't swallowed.

Tests

tests/console/test_run_command.py covers:

  • positional argument forwarding
  • non-zero exit code propagation
  • option forwarding after --
  • running a command with no extra args

All 4 pass; existing serve-command tests remain green.

Add a built-in 'run' console command that forwards arguments to another
registered command via Cleo's Command.call and propagates its exit code.

Usage:
  artisan run db:migrate
  artisan run db:seed -- --force

@bedus-creation bedus-creation left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review verdict: APPROVE (posting as a comment — GitHub blocks formal self-approval since the authenticated account authored this PR). Verified locally on branch task/run-console-command.

Review against the requested dimensions:

  1. Clean/minimal wrapper, no core abstraction changes ✅ — 35-line RunCommand + a single self.commands([PublishCommand, RunCommand]) line in AppProvider.boot(). No changes to Container/Application/Provider/Model.
  2. Exit-code propagation ✅ — handle() returns self.call(...) directly; test_propagates_non_zero_exit_code confirms exit_code=5 → status 5.
  3. Graceful unknown-command handling ✅ — an unknown name raises Cleo's CleoCommandNotFoundError, which the inherited ConsoleApplication/Cleo run loop renders as a clean The command "x" does not exist. message and exits non-zero (1). Verified empirically — no raw traceback.
  4. Meaningful test coverage ✅ — 4 tests (positional forwarding, exit-code propagation, option forwarding after --, no-args). All pass locally in 0.04s.
  5. Focused diff ✅ — no uv.lock, no version bumps; only the 4 intended files.

Code quality: type hints present, args or [] guards None, and the shlex.join([command, *forwarded]) leading-name trick is correct and well-documented.

Non-blocking nit (optional): consider adding a test that pins the unknown-command path (assert it surfaces CleoCommandNotFoundError / non-zero exit), since that behavior is currently only inherited, not locked by a test.

Holding merge until Console QA reports PASS on task #476, per PM.

@bedus-creation

Copy link
Copy Markdown
Contributor Author

Closing — this was the wrong interpretation. The requirement is a programmatic Application.run() API, not a new artisan CLI command. Superseded by the work in task #478.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant