Skip to content

Commit 0f18ed1

Browse files
committed
refactor(console): add isForced() to bypass CautionMiddleware
1 parent 814ddd4 commit 0f18ed1

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

packages/console/src/Console.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,9 @@ 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 function isForced(): bool;
160165
}

packages/console/src/GenericConsole.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function setForced(): self
7373
return $this;
7474
}
7575

76+
public function isForced(): bool
77+
{
78+
return $this->isForced;
79+
}
80+
7681
public function disablePrompting(): self
7782
{
7883
$this->supportsPrompting = false;

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)