Skip to content

Commit

Permalink
Make redis and ssh args consistent; allow multiple args in redis comm…
Browse files Browse the repository at this point in the history
…and (#1497)
  • Loading branch information
pjcdawkins authored Nov 22, 2024
1 parent 12e11ca commit 0842554
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/Command/Service/RedisCliCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function configure()
$this->setName('service:redis-cli');
$this->setAliases(['redis']);
$this->setDescription('Access the Redis CLI');
$this->addArgument('args', InputArgument::OPTIONAL, 'Arguments to add to the Redis command');
$this->addArgument('args', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Arguments to add to the Redis command');
Relationships::configureInput($this->getDefinition());
Ssh::configureInput($this->getDefinition());
$this->addProjectOption()
Expand Down Expand Up @@ -52,18 +52,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
$service['port']
);
if ($args = $input->getArgument('args')) {
$redisCommand .= ' ' . $args;
if (count($args) === 1) {
$redisCommand .= ' ' . $args[0];
} else {
$redisCommand .= ' ' . implode(' ', array_map([OsUtil::class, 'escapePosixShellArg'], $args));
}
} elseif ($this->isTerminal(STDIN) && $host instanceof RemoteHost) {
// Force TTY output when the input is a terminal.
$host->setExtraSshOptions(['RequestTTY yes']);
}

$this->stdErr->writeln(
sprintf('Connecting to Redis service via relationship <info>%s</info> on <info>%s</info>', $service['_relationship_name'], $host->getLabel())
);

// Force TTY output when the input is a terminal.
if ($this->isTerminal(STDIN) && $host instanceof RemoteHost) {
$host->setExtraSshOptions(['RequestTTY yes']);
}

return $host->runCommandDirect($redisCommand);
}
}
2 changes: 1 addition & 1 deletion src/Service/Ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private function getSshOptions($hostIsInternal)
* the command line.
* @param string[] $extraOptions
* SSH options, e.g. 'RequestTTY yes'.
* @param string|null $remoteCommand
* @param string[]|string|null $remoteCommand
* A remote command to run on the host.
* @param bool $omitUrl
* Omit the URL from the command. Use this if the URL is specified in
Expand Down

0 comments on commit 0842554

Please sign in to comment.