Skip to content

Commit

Permalink
Allow to use environment while disconnected from QIT
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Mar 6, 2024
1 parent bc0b597 commit 4f16e72
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
Binary file modified qit
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use function QIT_CLI\get_manager_url;

class OnboardingCommand extends Command {
protected static $defaultName = 'onboarding'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase
class ConnectCommand extends Command {
protected static $defaultName = 'connect'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase

protected function configure() {
$this
->setDescription( 'Runs the QIT CLI onboarding.' );
->setDescription( 'Connect to manage your extensions and test runs.' );
}

protected function execute( InputInterface $input, OutputInterface $output ): int {
Expand Down
6 changes: 3 additions & 3 deletions src/src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace QIT_CLI;

use QIT_CLI\Commands\OnboardingCommand;
use QIT_CLI\Commands\ConnectCommand;
use QIT_CLI\Exceptions\IOException;
use QIT_CLI\IO\Input;

Expand Down Expand Up @@ -75,7 +75,7 @@ public static function get_last_diagnosis(): int {
return (int) App::make( self::class )->get( 'last_diagnosis' ) ?: 0;
}

public static function needs_onboarding(): bool {
public static function needs_connection(): bool {
if ( defined( 'UNIT_TESTS' ) && UNIT_TESTS ) {
return false;
}
Expand All @@ -90,7 +90,7 @@ public static function needs_onboarding(): bool {
}

// Consistent behavior if we are running the onboarding command directly.
if ( App::make( Input::class )->getFirstArgument() === OnboardingCommand::getDefaultName() ) {
if ( App::make( Input::class )->getFirstArgument() === ConnectCommand::getDefaultName() ) {
return true;
}

Expand Down
46 changes: 18 additions & 28 deletions src/src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use QIT_CLI\Commands\Environment\UpEnvironmentCommand;
use QIT_CLI\Commands\GetCommand;
use QIT_CLI\Commands\ListCommand;
use QIT_CLI\Commands\OnboardingCommand;
use QIT_CLI\Commands\ConnectCommand;
use QIT_CLI\Commands\OpenCommand;
use QIT_CLI\Commands\Partner\AddPartner;
use QIT_CLI\Commands\Partner\RemovePartner;
Expand Down Expand Up @@ -157,27 +157,24 @@ public function filter( $in, $out, &$consumed, $closing ): int {
return $application;
}

if ( Config::needs_onboarding() ) {
try {
$application->add( $container->make( AddPartner::class ) );
$application->add( $container->make( AddBackend::class ) );

$onboarding = $container->make( OnboardingCommand::class );
$onboarding->setApplication( $application );
exit( $onboarding->run( $container->make( Input::class ), $container->make( Output::class ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} catch ( \Exception $e ) {
App::make( Output::class )->writeln( $e->getMessage() );
exit( 1 );
}
}

$is_connected_to_backend = false;

// Global commands.
$application->add( $container->make( DevModeCommand::class ) );
$application->add( $container->make( ConfigDirCommand::class ) );
$application->add( $container->make( OnboardingCommand::class ) );
$application->add( $container->make( ConnectCommand::class ) );

// Environment commands.
try {
$application->add( $container->make( UpEnvironmentCommand::class ) );
$application->add( $container->make( DownEnvironmentCommand::class ) );
$application->add( $container->make( RestartEnvironmentCommand::class ) );
$application->add( $container->make( ListEnvironmentCommand::class ) );
$application->add( $container->make( EnterEnvironmentCommand::class ) );
$application->add( $container->make( ExecEnvironmentCommand::class ) );
} catch ( \Exception $e ) {
App::make( Output::class )->writeln( $e->getMessage() );
}

// Partner commands.
$application->add( $container->make( AddPartner::class ) );
Expand Down Expand Up @@ -233,18 +230,11 @@ public function filter( $in, $out, &$consumed, $closing ): int {
// Dynamically crete Mass Test run command.
$container->make( CreateMassTestCommands::class )->register_commands( $application );
}

// Environment commands.
try {
$application->add( $container->make( UpEnvironmentCommand::class ) );
$application->add( $container->make( DownEnvironmentCommand::class ) );
$application->add( $container->make( RestartEnvironmentCommand::class ) );
$application->add( $container->make( ListEnvironmentCommand::class ) );
$application->add( $container->make( EnterEnvironmentCommand::class ) );
$application->add( $container->make( ExecEnvironmentCommand::class ) );
} catch ( \Exception $e ) {
App::make( Output::class )->writeln( $e->getMessage() );
}
} else {
$io = new Symfony\Component\Console\Style\SymfonyStyle( $container->make( Input::class ), $container->make( Output::class ) );
$io->section( 'Limited commands available' );
$io->writeln( sprintf( '<fg=black;bg=yellow>[Please run "%s %s" to connect to QIT.]</>', $argv[0], ConnectCommand::getDefaultName() ) );
$io->writeln( '' );
}

if ( $container->make( Output::class )->isVerbose() ) {
Expand Down

0 comments on commit 4f16e72

Please sign in to comment.