-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the clone command and adjust output
- Loading branch information
Showing
24 changed files
with
315 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace StellarWP\Pup\Commands; | ||
|
||
use StellarWP\Pup\App; | ||
use StellarWP\Pup\Command\Command; | ||
use StellarWP\Pup\Utils\Directory as DirectoryUtils; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Clone a git repository. | ||
* | ||
* This command is named CloneCommand because Clone is a reserved word in PHP. | ||
*/ | ||
class CloneCommand extends Command { | ||
/** | ||
* @inheritDoc | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() { | ||
$this->setName( 'clone' ) | ||
->setDescription( 'Clone a git repository.' ) | ||
->setHelp( 'Clone a git repository.' ); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function execute( InputInterface $input, OutputInterface $output ) { | ||
parent::execute( $input, $output ); | ||
$config = App::getConfig(); | ||
$build_dir = $config->getBuildDir(); | ||
$branch = $input->getOption( 'branch' ); | ||
|
||
$branch_arg = ''; | ||
if ( $branch ) { | ||
$branch_arg = "-b {$branch}"; | ||
} | ||
|
||
$repo = App::getConfig()->getRepo(); | ||
|
||
if ( file_exists( $build_dir ) ) { | ||
$build_dir_basename = basename( $build_dir ); | ||
$output->writeln( "The {$build_dir_basename} already exists." ); | ||
$output->write( "Removing build dir..." ); | ||
if ( file_exists( $build_dir ) && DirectoryUtils::rmdir( $build_dir ) !== 0 ) { | ||
throw new \Exception( "Could not remove {$build_dir}." ); | ||
} | ||
$output->write( 'Complete.' . PHP_EOL ); | ||
} | ||
|
||
$output->writeln( '<comment>Cloning the ' . $repo . ' repo into ' . App::getConfig()->getBuildDir( false ) . '...</comment>' ); | ||
system( 'git clone --quiet --recurse-submodules -j8 --shallow-submodules --depth 1 ' . $branch_arg . ' ' . $repo . ' ' . App::getConfig()->getBuildDir( false ) ); | ||
$output->writeln( '<fg=green>✓</> Clone complete.' ); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.