Skip to content

Commit 7a21e4a

Browse files
committed
Updated deferred cli server based on dogfooding
1 parent 966665b commit 7a21e4a

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

src/Commands/CommandRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function handle(Context $context): void
102102
array_pop($nameArgs);
103103
}
104104

105-
if ($this->default) {
105+
if (isset($this->default)) {
106106
$this->default->handle($context);
107107
} else {
108108
$this->showHelp($context);

src/Deferral/DeferredContextCliServer.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Closure;
88
use SlackPhp\Framework\{AppServer, Context, Exception};
9-
use SlackPhp\Framework\Auth\TokenStore;
109
use Throwable;
1110

1211
/**
@@ -18,7 +17,6 @@ class DeferredContextCliServer extends AppServer
1817
private array $args;
1918
private ?Closure $deserializeCallback;
2019
private int $exitCode = 0;
21-
private TokenStore $tokenStore;
2220

2321
/**
2422
* @param string[] $args
@@ -42,17 +40,6 @@ public function withDeserializeCallback(callable $deserializeCallback): self
4240
return $this;
4341
}
4442

45-
/**
46-
* @param TokenStore $tokenStore
47-
* @return $this
48-
*/
49-
public function withTokenStore(TokenStore $tokenStore): self
50-
{
51-
$this->tokenStore = $tokenStore;
52-
53-
return $this;
54-
}
55-
5643
protected function init(): void
5744
{
5845
global $argv;
@@ -61,28 +48,32 @@ protected function init(): void
6148

6249
public function start(): void
6350
{
51+
// Process args.
52+
$serializedContext = $this->args[1] ?? '';
53+
$softExit = ($this->args[2] ?? '') === '--soft-exit';
54+
55+
// Run the app.
6456
try {
6557
$this->getLogger()->debug('Started processing of deferred context');
66-
$context = $this->deserializeContext($this->args[1] ?? '');
67-
if (isset($this->tokenStore)) {
68-
$context->withTokenStore($this->tokenStore);
69-
}
58+
$context = $this->deserializeContext($serializedContext);
59+
$this->getAppCredentials();
7060
$this->getApp()->handle($context);
7161
$this->getLogger()->debug('Completed processing of deferred context');
7262
} catch (Throwable $exception) {
7363
$this->getLogger()->error('Error occurred during processing of deferred context', compact('exception'));
7464
$this->exitCode = 1;
7565
}
7666

77-
$this->stop();
67+
if (!$softExit) {
68+
$this->stop();
69+
}
7870
}
7971

72+
/**
73+
* @return never-returns
74+
*/
8075
public function stop(): void
8176
{
82-
if (isset($this->args[2]) && $this->args[2] === '--soft-exit') {
83-
return;
84-
}
85-
8677
exit($this->exitCode);
8778
}
8879

0 commit comments

Comments
 (0)