Skip to content

Commit bccf92f

Browse files
xHeaveninnocenzi
andauthored
fix(console)!: allow --force to bypass CautionMiddleware (#1804)
Co-authored-by: Enzo Innocenzi <[email protected]>
1 parent 814ddd4 commit bccf92f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

packages/console/src/Console.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,11 @@ public function supportsPrompting(): bool;
157157
* Forces the console to not be interactive.
158158
*/
159159
public function disablePrompting(): self;
160+
161+
/**
162+
* Whether the console is in forced mode (skipping confirmations).
163+
*/
164+
public bool $isForced {
165+
get;
166+
}
160167
}

packages/console/src/GenericConsole.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class GenericConsole implements Console
3939

4040
private ?string $label = null;
4141

42-
private bool $isForced = false;
42+
private(set) bool $isForced = false;
4343

4444
private bool $supportsPrompting = true;
4545

packages/console/src/Middleware/CautionMiddleware.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next
2525
$environment = $this->appConfig->environment;
2626

2727
if ($environment->isProduction() || $environment->isStaging()) {
28+
if ($this->console->isForced) {
29+
return $next($invocation);
30+
}
31+
2832
$continue = $this->console->confirm('This command might be destructive. Do you wish to continue?');
2933

3034
if (! $continue) {

0 commit comments

Comments
 (0)