Skip to content

feat: add global --application and --environment flags#64

Open
JoshSalway wants to merge 3 commits intolaravel:mainfrom
JoshSalway:feature/application-environment-flags
Open

feat: add global --application and --environment flags#64
JoshSalway wants to merge 3 commits intolaravel:mainfrom
JoshSalway:feature/application-environment-flags

Conversation

@JoshSalway
Copy link

Summary

  • Adds --application and --environment as global options on all commands via BaseCommand::configure()
  • Threads these flag values through the Resolvers container to ApplicationResolver and EnvironmentResolver
  • Resolution priority: explicit flag > local config > git remote/branch detection > interactive prompt
  • Enables CI/CD usage where commands are not run from within a matching project directory

Example usage

cloud environment:list --application=fraghub --no-interaction
cloud command:list --application=fraghub --environment=main --no-interaction

Changes

  • app/Commands/BaseCommand.php — adds global --application and --environment options in configure(), passes them to Resolvers
  • app/Resolvers/Resolver.php — accepts applicationFlag and environmentFlag constructor params
  • app/Resolvers/Resolvers.php — accepts and threads flag values to resolver instances
  • app/Resolvers/ApplicationResolver.php — checks applicationFlag before local config fallback
  • app/Resolvers/EnvironmentResolver.php — checks environmentFlag before local config fallback

Test plan

  • ./vendor/bin/phpstan analyse passes with no errors
  • ./vendor/bin/pest passes (378 tests, 409 assertions)
  • Manual test: cloud environment:list --application=<name> --no-interaction resolves without git context
  • Manual test: cloud command:list --application=<name> --environment=<name> --no-interaction resolves without git context

Closes #61, refs #62

🤖 Generated with Claude Code

Josh Salway and others added 3 commits March 17, 2026 02:51
Increases test coverage from 3/87 commands (~3%) to 43/87 (~49%),
following the Laravel Forge CLI pattern of one test file per command.

Commands now tested:
- Auth: auth, auth:token
- Application: create, get, update, delete
- Environment: create, get, list, update, delete, variables
- Domain: create, delete, list, verify
- Database: cluster create/delete/list, database create/delete/list
- Cache: create, delete, list
- Bucket: create, delete, list
- Instance: create, delete, list, update
- WebSocket: cluster create/delete/list, application create/delete
- Background Process: create, delete, list
- Command: run, list

Bugs documented in tests (skipped with references to PR laravel#42):
- 7 commands catch wrong RequestException class (Illuminate vs Saloon)
- ApplicationUpdate has no error handling for API failures
- DatabaseDelete catches Throwable which swallows CommandExitException
- DomainCreate missing non-interactive defaults
- CacheDelete/BucketDelete missing --json option

Refs laravel#41

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…3 files

Coverage now at ~95% of commands (80/87). Remaining untested:
Browser, Dashboard, Completions (utility commands that open browser/generate shell),
Ship (tested via refactor PR laravel#54), and DeployMonitor (complex polling).

New test files cover:
- Application: list (expanded)
- BackgroundProcess: get, update
- Bucket: get, update
- BucketKey: create, delete, get, list, update
- Cache: get, types, update
- Command: get
- DatabaseCluster: get, update
- Database: get, open, restore create
- DatabaseSnapshot: create, delete, get, list
- DedicatedCluster: list
- Deployment: get, list
- DeployMonitor: basic smoke test
- Domain: get, update
- EnvironmentLogs: basic test
- Instance: get, sizes
- IpAddresses: list, filter
- AuthToken: list, reveal
- WebSocket: app get/list/update, cluster get/update
- RepoConfig: git detection

Additional bugs found and filed:
- laravel#55: DatabaseRestoreCreate completely broken (TypeError)
- laravel#56: DatabaseSnapshotCreate missing CLI options
- laravel#57: DatabaseClusterUpdate unusable non-interactively

352 tests, 381 assertions, 0 failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add global options to BaseCommand so that application and environment
can be specified explicitly via --application and --environment flags,
removing the requirement to run commands from within a matching project
directory. The resolution priority is: explicit flag > local config >
git remote/branch detection > interactive prompt.

Closes laravel#61, refs laravel#62

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Feature: --application and --environment flags for commands that need repo context

1 participant