Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .github/workflows/update-wp-cli-commands

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/update-wp-cli-commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Update WP-CLI Commands List
on:
workflow_dispatch:
schedule:
# Once a day at 6am
- cron: "0 6 * * *"
jobs:
wp-cli:
name: WP CLI Commands List
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
fail-fast: true
steps:
- name: Check out source code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: wp-cli, composer

- name: Generate WP-CLI Commands List
run: wp cli cmd-dump > ${{ runner.temp }}/wpcli-commands.json

- name: Get WP-CLI version
run: wp --version > ${{ runner.temp }}/wpcli-version.txt

- name: Ingest WP-CLI Commands List
run: cd cli && composer install && ./bin/docsdangit ingest --source=wp-cli --cli-dump-path=${{ runner.temp }}/wpcli-commands.json --cli-version-path=${{ runner.temp }}/wpcli-version.txt
8 changes: 6 additions & 2 deletions cli/src/Command/Ingest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ protected function configure()
->setDescription("Ingest docs")
->setDefinition(
new InputDefinition([
new InputOption('source', 's', InputOption::VALUE_OPTIONAL, 'Docs source (wp-docs, php-docs, wp-cli, wp-dev). All sources by default.')
new InputOption('source', 's', InputOption::VALUE_OPTIONAL, 'Docs source (wp-docs, php-docs, wp-cli, wp-dev). All sources by default.'),
new InputOption('cli-dump-path', 'dp', InputOption::VALUE_OPTIONAL, 'WP CLI dump file path'),
new InputOption('cli-version-path', 'vp', InputOption::VALUE_OPTIONAL, 'WP CLI version file path')
])
);
}
Expand All @@ -53,7 +55,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
if( ! $source || 'wp-cli' === $source ) {
$output->writeln('🚀 Ingesting WP CLI Docs...');
$wp_docs = new WP_CLI();
$cli_dump_path = $input->getOption('cli-dump-path');
$cli_version_path = $input->getOption('cli-version-path');
$wp_docs = new WP_CLI( $cli_dump_path, $cli_version_path );
$wp_docs->parse();
}
if( ! $source || 'php-docs' === $source ) {
Expand Down
16 changes: 11 additions & 5 deletions cli/src/Parsers/WP_CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@

class WP_CLI implements Parser {
private $wp_cli_version;
private $dump_path = 'data/wpcli-commands.json';
private $cli_version_path = 'data/wpcli-version.txt';

public function __construct() {
public function __construct( $dump_path = null, $cli_version_path = null ) {
$this->wp_cli_version = $this->get_source_version();
if( $dump_path ) {
$this->dump_path = $dump_path;
}
if( $cli_version_path ) {
$this->cli_version_path = $cli_version_path;
}
}

public function parse() {
$file = 'data/wpcli-commands.json';
$raw = file_get_contents( $file );
$raw = file_get_contents( $this->dump_path );
$json = json_decode( $raw );
$this->process_subcommands( $json->subcommands, 'https://developer.wordpress.org/cli/commands/', [] );
}

public function get_source_version() {
$file = 'data/wpcli-version.txt';
$raw = file_get_contents( $file );
$raw = file_get_contents( $this->cli_version_path );
return str_replace("WP-CLI ", "", $raw);
}

Expand Down