From 1ba1804d063a829f13f1edd35bd17143de4b1e29 Mon Sep 17 00:00:00 2001 From: David Beja Date: Mon, 10 Apr 2023 17:04:56 +0100 Subject: [PATCH 1/4] Rename update-wp-cli-commands to update-wp-cli-commands.yml --- .../{update-wp-cli-commands => update-wp-cli-commands.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{update-wp-cli-commands => update-wp-cli-commands.yml} (100%) diff --git a/.github/workflows/update-wp-cli-commands b/.github/workflows/update-wp-cli-commands.yml similarity index 100% rename from .github/workflows/update-wp-cli-commands rename to .github/workflows/update-wp-cli-commands.yml From 82271e46ab6df79aec9113033df98353e88c4ad7 Mon Sep 17 00:00:00 2001 From: David Beja Date: Mon, 10 Apr 2023 17:15:47 +0100 Subject: [PATCH 2/4] Ingest WP-CLI commands list --- .github/workflows/update-wp-cli-commands.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-wp-cli-commands.yml b/.github/workflows/update-wp-cli-commands.yml index 83e108f..26ee889 100644 --- a/.github/workflows/update-wp-cli-commands.yml +++ b/.github/workflows/update-wp-cli-commands.yml @@ -19,7 +19,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - tools: wp-cli + tools: wp-cli, composer - name: Generate WP-CLI Commands List run: wp cli cmd-dump > ${{ github.workspace }}/cli/data/wpcli-commands.json @@ -35,3 +35,6 @@ jobs: commit_user_name: 'GitHub Actions' commit_user_email: 'github-actions[bot]@users.noreply.github.com' commit_author: 'GitHub Actions ' + + - name: Ingest WP-CLI Commands List + run: cd cli && composer install && ./bin/docsdangit ingest -s wp-cli From b873183d233a0d84a201fdc16d431bbf6e320533 Mon Sep 17 00:00:00 2001 From: David Beja Date: Wed, 12 Apr 2023 17:55:17 +0100 Subject: [PATCH 3/4] Add wp-cli dump and version path args to cli --- cli/src/Command/Ingest.php | 8 ++++++-- cli/src/Parsers/WP_CLI.php | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cli/src/Command/Ingest.php b/cli/src/Command/Ingest.php index 0ae415d..b092f13 100644 --- a/cli/src/Command/Ingest.php +++ b/cli/src/Command/Ingest.php @@ -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') ]) ); } @@ -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 ) { diff --git a/cli/src/Parsers/WP_CLI.php b/cli/src/Parsers/WP_CLI.php index db6fcfe..5e874bf 100644 --- a/cli/src/Parsers/WP_CLI.php +++ b/cli/src/Parsers/WP_CLI.php @@ -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); } From b290518185881ab18164372842a1fe8286920658 Mon Sep 17 00:00:00 2001 From: David Beja Date: Wed, 12 Apr 2023 18:12:13 +0100 Subject: [PATCH 4/4] Remove commit and add paths args to cli --- .github/workflows/update-wp-cli-commands.yml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/update-wp-cli-commands.yml b/.github/workflows/update-wp-cli-commands.yml index 26ee889..065b3d5 100644 --- a/.github/workflows/update-wp-cli-commands.yml +++ b/.github/workflows/update-wp-cli-commands.yml @@ -22,19 +22,10 @@ jobs: tools: wp-cli, composer - name: Generate WP-CLI Commands List - run: wp cli cmd-dump > ${{ github.workspace }}/cli/data/wpcli-commands.json + run: wp cli cmd-dump > ${{ runner.temp }}/wpcli-commands.json - name: Get WP-CLI version - run: wp --version > ${{ github.workspace }}/cli/data/wpcli-version.txt + run: wp --version > ${{ runner.temp }}/wpcli-version.txt - - name: Commit any changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: 'Update WP-CLI Commands List' - commit_options: '--no-verify' - commit_user_name: 'GitHub Actions' - commit_user_email: 'github-actions[bot]@users.noreply.github.com' - commit_author: 'GitHub Actions ' - - name: Ingest WP-CLI Commands List - run: cd cli && composer install && ./bin/docsdangit ingest -s wp-cli + 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