diff --git a/src/ASMP.php b/src/ASMP.php index 93375ca..3380f5b 100644 --- a/src/ASMP.php +++ b/src/ASMP.php @@ -11,6 +11,7 @@ namespace ASMP\WordPressIntegration; interface ASMP { - public const VERSION = 'ASMP_DISCOVERY_VERSION'; + + public const VERSION = 'ASMP_DISCOVERY_VERSION'; public const ENDPOINT = 'ASMP_DISCOVERY_ENDPOINT'; } diff --git a/src/Console/AsmpCommand.php b/src/Console/AsmpCommand.php index 8a1f298..121a74d 100644 --- a/src/Console/AsmpCommand.php +++ b/src/Console/AsmpCommand.php @@ -9,6 +9,7 @@ namespace ASMP\WordPressIntegration\Console; +use ASMP\WordPressIntegration\ASMP; use WP_CLI; final class AsmpCommand { @@ -16,30 +17,30 @@ final class AsmpCommand { /** * Run a check against ASMP. * - * @param array $args Positional arguments. - * @param array $assoc_args Associative arguments. + * @param array $args Optional. Array of positional arguments. + * @param array $assoc_args Optional. Array of associative arguments. */ - public function check( array $args, array $assoc_args ) { + public function check( array $args, array $assoc_args ): void { WP_CLI::error( 'Not implemented yet' ); } /** * Request a change through ASMP. * - * @param array $args Positional arguments. - * @param array $assoc_args Associative arguments. + * @param array $args Optional. Array of positional arguments. + * @param array $assoc_args Optional. Array of associative arguments. */ - public function change( array $args, array $assoc_args ) { + public function change( array $args = [], array $assoc_args = [] ): void { WP_CLI::error( 'Not implemented yet' ); } /** * Roll back a change through ASMP. * - * @param array $args Positional arguments. - * @param array $assoc_args Associative arguments. + * @param array $args Optional. Array of positional arguments. + * @param array $assoc_args Optional. Array of associative arguments. */ - public function rollback( array $args, array $assoc_args ) { + public function rollback( array $args = [], array $assoc_args = [] ): void { WP_CLI::error( 'Not implemented yet' ); } @@ -51,10 +52,39 @@ public function rollback( array $args, array $assoc_args ) { * * : ID of the change to roll back. * - * @param array $args Positional arguments. - * @param array $assoc_args Associative arguments. + * @param array $args Optional. Array of positional arguments. + * @param array $assoc_args Optional. Array of associative arguments. */ - public function status( array $args, array $assoc_args ) { + public function status( array $args = [], array $assoc_args = [] ): void { WP_CLI::error( 'Not implemented yet' ); } + + /** + * Check whether ASMP is available. + * + * @subcommand is-available + * @param array $args Optional. Array of positional arguments. + * @param array $assoc_args Optional. Array of associative arguments. + */ + public function is_available( array $args = [], array $assoc_args = [] ): void { + if ( false === \getenv( ASMP::VERSION ) ) { + exit( 1 ); + } + + exit( 0 ); + } + + /** + * Get the supported version of ASMP. + * + * @param array $args Optional. Array of positional arguments. + * @param array $assoc_args Optional. Array of associative arguments. + */ + public function version( array $args = [], array $assoc_args = [] ): void { + if ( ! $this->is_available() ) { + WP_CLI::error( 'ASMP is not available.' ); + } + + WP_CLI::log( \getenv( ASMP::VERSION ) ); + } }