Skip to content

Commit

Permalink
Use proper endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Mar 25, 2019
1 parent 9e6d05e commit bbfed2f
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/Console/AsmpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ final class AsmpCommand {
* Instantiate a AsmpCommand object.
*/
public function __construct() {
$this->config = Configuration::getDefaultConfiguration();
if ( ! $this->is_supported() ) {
return;
}

$this->config = Configuration::getDefaultConfiguration()
->setHost( $this->get_endpoint() );
}

/**
Expand Down Expand Up @@ -120,11 +125,7 @@ public function status( array $args = [], array $assoc_args = [] ): void {
* @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 );
exit( $this->is_supported() ? 0 : 1 );
}

/**
Expand All @@ -136,7 +137,7 @@ public function is_available( array $args = [], array $assoc_args = [] ): void {
public function version( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

WP_CLI::log( \getenv( ASMP::VERSION ) );
WP_CLI::log( $this->get_version() );
}

/**
Expand All @@ -148,7 +149,7 @@ public function version( array $args = [], array $assoc_args = [] ): void {
public function endpoint( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

WP_CLI::log( \getenv( ASMP::ENDPOINT ) );
WP_CLI::log( $this->get_endpoint() );
}

/**
Expand All @@ -160,6 +161,24 @@ private function is_supported(): bool {
return false !== \getenv( ASMP::VERSION );
}

/**
* Get the version of ASMP.
*
* @return string ASMP version.
*/
private function get_version(): string {
return \getenv( ASMP::VERSION );
}

/**
* Get the endpoint for ASMP.
*
* @return string ASMP endpoint.
*/
private function get_endpoint(): string {
return \getenv( ASMP::ENDPOINT );
}

/**
* Ensure that ASMP is available.
*
Expand Down

0 comments on commit bbfed2f

Please sign in to comment.