Skip to content

Commit

Permalink
Merge pull request #15 from wirecli/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
flydev-fr authored Sep 7, 2024
2 parents 70145b7 + 013397d commit 74d6963
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/Commands/Common/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ class NewCommand extends PWConnector {
private $projectName;
private $projectDir;
private $version;
private $helper;
private $compressedFilePath;
private $requirementsErrors = array();
private $src;
private $installer;
private $verbose;
protected $downloader;
protected $tools;

/**
Expand All @@ -66,7 +70,7 @@ class NewCommand extends PWConnector {
'userpass' => '',
'userpass_confirm' => '',
'useremail' => '',
'color' => 'classic',
'color' => 'classic'
);

/**
Expand All @@ -82,6 +86,7 @@ protected function configure() {
->setName('new')
->setDescription('Creates a new ProcessWire project')
->addArgument('directory', InputArgument::OPTIONAL, 'Directory where the new project will be created')
->addOption('force', null, InputOption::VALUE_NONE, 'Force installation in an non empty directory')
->addOption('dbUser', null, InputOption::VALUE_REQUIRED, 'Database user')
->addOption('dbPass', null, InputOption::VALUE_OPTIONAL, 'Database password')
->addOption('dbName', null, InputOption::VALUE_REQUIRED, 'Database name')
Expand Down Expand Up @@ -410,9 +415,10 @@ private function download($branch) {
* @throws \RuntimeException if the downloaded archive could not be extracted
*/
private function extract() {
$forceInstall = $this->input->getOption('force');
$this->tools->writeBlockBasic('Preparing project...');
$cfp = $this->src ? $this->src : $this->compressedFilePath;
$this->downloader->extract($cfp, $this->projectDir, $this->getName());
$this->downloader->extract($cfp, $this->projectDir, $this->getName(), $forceInstall);

return $this;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Commands/Common/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
class ServeCommand extends PwConnector {

private $helper = null;


/**
* Configures the current command.
*/
Expand Down
21 changes: 14 additions & 7 deletions src/Helpers/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Downloader {
private $version;
private $output;
private $tools;
private $compressedFilePath;

/**
* Construct Downloader
Expand Down Expand Up @@ -154,7 +155,7 @@ public function download($uri, $prefix = 'pw') {
* @param string $to
* @param string $name
*/
public function extract($from, $to, $name = '') {
public function extract($from, $to, $name = '', $force = false) {
//var_dump($from, $to, $name);exit;
$source = $name ? 'ProcessWire' : 'the module';

Expand All @@ -164,12 +165,18 @@ public function extract($from, $to, $name = '') {
}

// check for empty directory
$filesInsideDir = new \FilesystemIterator($to, \FilesystemIterator::SKIP_DOTS);
if (iterator_count($filesInsideDir) > 1) {
throw new \RuntimeException(sprintf(
"ProcessWire can't be installed because the target folder `%s` is not empty.\n" .
"Use an empty directory or provide an argument where the new project will be created like `wire-cli new <dirname>`",
$to));
if (!$force) {
$filesInsideDir = new \FilesystemIterator($to, \FilesystemIterator::SKIP_DOTS);
if (iterator_count($filesInsideDir) > 1) {
throw new \RuntimeException(sprintf(
"ProcessWire can't be installed because the target folder `%s` is not empty.\n" .
"Use an empty directory or provide an argument where the new project will be created like `wire-cli new <dirname>`.\n" .
"Use option --force to proceed the installation in a non empty directory.",
$to));
}
}
else {
$this->tools->writeWarning("ProcessWire will be installed in a non-empty dir (--force found on command-line).\n");
}

try {
Expand Down
1 change: 1 addition & 0 deletions src/Helpers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
class Installer {

protected $fs = null;
protected $v = true;

/**
* Whether or not we force installed files to be copied.
Expand Down
16 changes: 15 additions & 1 deletion src/Helpers/WsTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
protected $helper;
protected $input;

protected static $types = array('error', 'success', 'info', 'comment', 'link', 'header', 'mark');
protected static $types = array('error', 'warning', 'success', 'info', 'comment', 'link', 'header', 'mark');

/**
* Construct WsTools
Expand Down Expand Up @@ -51,6 +51,9 @@ public function __construct(OutputInterface $output) {

$style = new OutputFormatterStyle('blue', 'white', array('reverse'));
$output->getFormatter()->setStyle('mark', $style);

$style = new OutputFormatterStyle('yellow', null, array('bold'));
$output->getFormatter()->setStyle('warning', $style);
}

/**
Expand Down Expand Up @@ -167,6 +170,17 @@ public function writeErrorAndExit($string) {
public function writeComment($string, $write = true) {
return $this->write($string, 'comment', $write);
}

/**
* Simple method for coloring warning output
*
* @param string $string
* @param boolean $write
* @return tinted string
*/
public function writeWarning($string, $write = true) {
return $this->write($string, 'warning', $write);
}

/**
* Simple method for coloring info output
Expand Down

0 comments on commit 74d6963

Please sign in to comment.