Skip to content

Commit 74d6963

Browse files
authored
Merge pull request #15 from wirecli/dev
Dev
2 parents 70145b7 + 013397d commit 74d6963

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

src/Commands/Common/NewCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ class NewCommand extends PWConnector {
4141
private $projectName;
4242
private $projectDir;
4343
private $version;
44+
private $helper;
4445
private $compressedFilePath;
4546
private $requirementsErrors = array();
47+
private $src;
4648
private $installer;
49+
private $verbose;
50+
protected $downloader;
4751
protected $tools;
4852

4953
/**
@@ -66,7 +70,7 @@ class NewCommand extends PWConnector {
6670
'userpass' => '',
6771
'userpass_confirm' => '',
6872
'useremail' => '',
69-
'color' => 'classic',
73+
'color' => 'classic'
7074
);
7175

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

417423
return $this;
418424
}

src/Commands/Common/ServeCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020
class ServeCommand extends PwConnector {
2121

22+
private $helper = null;
23+
24+
2225
/**
2326
* Configures the current command.
2427
*/

src/Helpers/Downloader.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Downloader {
2525
private $version;
2626
private $output;
2727
private $tools;
28+
private $compressedFilePath;
2829

2930
/**
3031
* Construct Downloader
@@ -154,7 +155,7 @@ public function download($uri, $prefix = 'pw') {
154155
* @param string $to
155156
* @param string $name
156157
*/
157-
public function extract($from, $to, $name = '') {
158+
public function extract($from, $to, $name = '', $force = false) {
158159
//var_dump($from, $to, $name);exit;
159160
$source = $name ? 'ProcessWire' : 'the module';
160161

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

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

175182
try {

src/Helpers/Installer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
class Installer {
3232

3333
protected $fs = null;
34+
protected $v = true;
3435

3536
/**
3637
* Whether or not we force installed files to be copied.

src/Helpers/WsTools.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
protected $helper;
2424
protected $input;
2525

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

2828
/**
2929
* Construct WsTools
@@ -51,6 +51,9 @@ public function __construct(OutputInterface $output) {
5151

5252
$style = new OutputFormatterStyle('blue', 'white', array('reverse'));
5353
$output->getFormatter()->setStyle('mark', $style);
54+
55+
$style = new OutputFormatterStyle('yellow', null, array('bold'));
56+
$output->getFormatter()->setStyle('warning', $style);
5457
}
5558

5659
/**
@@ -167,6 +170,17 @@ public function writeErrorAndExit($string) {
167170
public function writeComment($string, $write = true) {
168171
return $this->write($string, 'comment', $write);
169172
}
173+
174+
/**
175+
* Simple method for coloring warning output
176+
*
177+
* @param string $string
178+
* @param boolean $write
179+
* @return tinted string
180+
*/
181+
public function writeWarning($string, $write = true) {
182+
return $this->write($string, 'warning', $write);
183+
}
170184

171185
/**
172186
* Simple method for coloring info output

0 commit comments

Comments
 (0)