Skip to content

Commit

Permalink
CLI-1237: Publish docs (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored Jan 10, 2024
1 parent ab80a73 commit 1642bda
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
with:
files: var/acli.phar
- name: Publish docs
if: github.event_name == 'push'
run: |
./bin/acli self:make-docs -d docs
aws s3 sync docs s3://acquia-cli/docs
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

# Require all checks to pass without having to enumerate them in the branch protection UI.
# @see https://github.community/t/is-it-possible-to-require-all-github-actions-tasks-to-pass-without-enumerating-them/117957
check:
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Auth/AuthLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$activeKey = $this->datastoreCloud->get('acli_key');
if ($activeKey) {
$activeKeyLabel = $keys[$activeKey]['label'];
$output->write("The following Cloud Platform API key is active: <options=bold>$activeKeyLabel</>");
$output->writeln("The following Cloud Platform API key is active: <options=bold>$activeKeyLabel</>");
}
else {
$output->write('No Cloud Platform API key is active');
$output->writeln('No Cloud Platform API key is active');
}

// If keys already are saved locally, prompt to select.
Expand Down
2 changes: 0 additions & 2 deletions src/Command/Self/ClearCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Acquia\Cli\Command\Self;

use Acquia\Cli\Attribute\RequireAuth;
use Acquia\Cli\Command\CommandBase;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -13,7 +12,6 @@
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;

#[RequireAuth]
#[AsCommand(name: 'self:clear-caches', description: 'Clears local Acquia CLI caches', aliases: ['cc', 'cr'])]
final class ClearCacheCommand extends CommandBase {

Expand Down
35 changes: 30 additions & 5 deletions src/Command/Self/MakeDocsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,55 @@

namespace Acquia\Cli\Command\Self;

use Acquia\Cli\Attribute\RequireAuth;
use Acquia\Cli\Command\CommandBase;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;

#[RequireAuth]
#[AsCommand(name: 'self:make-docs', description: 'Generate documentation for all ACLI commands', hidden: TRUE)]
final class MakeDocsCommand extends CommandBase {

protected function configure(): void {
$this->addOption('format', 'f', InputOption::VALUE_OPTIONAL, 'The format to describe the docs in.', 'rst');
$this->addOption('dump', 'd', InputOption::VALUE_OPTIONAL, 'Dump docs to directory');
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$helper = new DescriptorHelper();

$helper->describe($output, $this->getApplication(), [
'format' => $input->getOption('format'),
if (!$input->getOption('dump')) {
$helper->describe($output, $this->getApplication(), [
'format' => $input->getOption('format'),
]);
return Command::SUCCESS;
}

$docs_dir = $input->getOption('dump');
$this->localMachineHelper->getFilesystem()->mkdir($docs_dir);
$buffer = new BufferedOutput();
$helper->describe($buffer, $this->getApplication(), [
'format' => 'json',
]);

$commands = json_decode($buffer->fetch(), TRUE);
$index = [];
foreach ($commands['commands'] as $command) {
if ($command['definition']['hidden'] ?? FALSE) {
continue;
}
$filename = $command['name'] . '.json';
$index[] = [
'command' => $command['name'],
'help' => $command['help'],
'path' => $filename,
'usage' => $command['usage'][0],
];
file_put_contents("$docs_dir/$filename", json_encode($command));
}
file_put_contents("$docs_dir/index.json", json_encode($index));
return Command::SUCCESS;
}

Expand Down

0 comments on commit 1642bda

Please sign in to comment.