Skip to content

Commit

Permalink
Always ensure ASMP is available
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Mar 25, 2019
1 parent fb910a0 commit a49e414
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/Console/AsmpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class AsmpCommand {
* @param array $assoc_args Optional. Array of associative arguments.
*/
public function check( array $args, array $assoc_args ): void {
$this->ensure_asmp_is_available();

WP_CLI::error( 'Not implemented yet' );
}

Expand All @@ -31,6 +33,8 @@ public function check( array $args, array $assoc_args ): void {
* @param array $assoc_args Optional. Array of associative arguments.
*/
public function change( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

WP_CLI::error( 'Not implemented yet' );
}

Expand All @@ -41,6 +45,8 @@ public function change( array $args = [], array $assoc_args = [] ): void {
* @param array $assoc_args Optional. Array of associative arguments.
*/
public function rollback( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

WP_CLI::error( 'Not implemented yet' );
}

Expand Down Expand Up @@ -81,10 +87,40 @@ public function is_available( array $args = [], array $assoc_args = [] ): void {
* @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.' );
}
$this->ensure_asmp_is_available();

WP_CLI::log( \getenv( ASMP::VERSION ) );
}

/**
* Get the provided endpoint of ASMP.
*
* @param array $args Optional. Array of positional arguments.
* @param array $assoc_args Optional. Array of associative arguments.
*/
public function endpoint( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

WP_CLI::log( \getenv( ASMP::VERSION ) );
}

/**
* Check whether ASMP is supported.
*
* @return bool Whether ASMP is supported.
*/
private function is_supported(): bool {
return false !== \getenv( ASMP::VERSION );
}

/**
* Ensure that ASMP is available.
*
* Throws a WP_CLI error and exits the process if not.
*/
private function ensure_asmp_is_available(): void {
if ( ! $this->is_supported() ) {
WP_CLI::error( 'ASMP is not available.' );
}
}
}

0 comments on commit a49e414

Please sign in to comment.