Skip to content

Commit

Permalink
Notifying of -v option and making output better for recipe info
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Dec 11, 2019
1 parent a21fb47 commit 5f5078a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/Command/SyncRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io = $this->getIO();

if (!$io->isVerbose()) {
$io->writeError([
'Run command with <info>-v</info> to see more details',
'',
]);
}

if ($targetPackages = $input->getArgument('packages')) {
if ($invalidPackages = array_diff($targetPackages, $totalPackages)) {
$io->writeError(sprintf('<warning>Cannot update: some packages are not installed:</warning> %s', implode(', ', $invalidPackages)));
Expand Down
16 changes: 8 additions & 8 deletions src/Configurator/CopyFromPackageConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CopyFromPackageConfigurator extends AbstractConfigurator
{
public function configure(Recipe $recipe, $config, Lock $lock, array $options = [])
{
$this->write('Setting configuration and copying files');
$this->write('Copying files from package');
$packageDir = $this->composer->getInstallationManager()->getInstallPath($recipe->getPackage());
$options = array_merge($this->options->toArray(), $options);

Expand All @@ -31,7 +31,7 @@ public function configure(Recipe $recipe, $config, Lock $lock, array $options =

public function unconfigure(Recipe $recipe, $config, Lock $lock)
{
$this->write('Removing configuration and files');
$this->write('Removing files from package');
$packageDir = $this->composer->getInstallationManager()->getInstallPath($recipe->getPackage());
$this->removeFiles($config, $packageDir, $this->options->get('root-dir'));
}
Expand All @@ -47,7 +47,7 @@ private function copyFiles(array $manifest, string $from, array $options)
$targetPath = $this->path->concatenate([$to, $target]);
if (!is_dir(\dirname($targetPath))) {
mkdir(\dirname($targetPath), 0777, true);
$this->write(sprintf('Created <fg=green>"%s"</>', $this->path->relativize(\dirname($targetPath))));
$this->write(sprintf(' Created <fg=green>"%s"</>', $this->path->relativize(\dirname($targetPath))));
}

$this->copyFile($this->path->concatenate([$from, $source]), $targetPath, $options);
Expand All @@ -65,7 +65,7 @@ private function removeFiles(array $manifest, string $from, string $to)
$targetPath = $this->path->concatenate([$to, $target]);
if (file_exists($targetPath)) {
@unlink($targetPath);
$this->write(sprintf('Removed <fg=green>"%s"</>', $this->path->relativize($targetPath)));
$this->write(sprintf(' Removed <fg=green>"%s"</>', $this->path->relativize($targetPath)));
}
}
}
Expand All @@ -83,7 +83,7 @@ private function copyDir(string $source, string $target, array $options)
if ($item->isDir()) {
if (!is_dir($targetPath)) {
mkdir($targetPath);
$this->write(sprintf('Created <fg=green>"%s"</>', $this->path->relativize($targetPath)));
$this->write(sprintf(' Created <fg=green>"%s"</>', $this->path->relativize($targetPath)));
}
} elseif (!file_exists($targetPath)) {
$this->copyFile($item, $targetPath, $options);
Expand All @@ -104,7 +104,7 @@ public function copyFile(string $source, string $target, array $options)

file_put_contents($target, $this->options->expandTargetDir(file_get_contents($source)));
@chmod($target, fileperms($target) | (fileperms($source) & 0111));
$this->write(sprintf('Created <fg=green>"%s"</>', $this->path->relativize($target)));
$this->write(sprintf(' Created <fg=green>"%s"</>', $this->path->relativize($target)));
}

private function removeFilesFromDir(string $source, string $target)
Expand All @@ -115,10 +115,10 @@ private function removeFilesFromDir(string $source, string $target)
if ($item->isDir()) {
// that removes the dir only if it is empty
@rmdir($targetPath);
$this->write(sprintf('Removed directory <fg=green>"%s"</>', $this->path->relativize($targetPath)));
$this->write(sprintf(' Removed directory <fg=green>"%s"</>', $this->path->relativize($targetPath)));
} else {
@unlink($targetPath);
$this->write(sprintf('Removed <fg=green>"%s"</>', $this->path->relativize($targetPath)));
$this->write(sprintf(' Removed <fg=green>"%s"</>', $this->path->relativize($targetPath)));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Configurator/CopyFromRecipeConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class CopyFromRecipeConfigurator extends AbstractConfigurator
{
public function configure(Recipe $recipe, $config, Lock $lock, array $options = [])
{
$this->write('Setting configuration and copying files');
$this->write('Copying files from recipe');
$options = array_merge($this->options->toArray(), $options);

$lock->add($recipe->getName(), ['files' => $this->copyFiles($config, $recipe->getFiles(), $options)]);
}

public function unconfigure(Recipe $recipe, $config, Lock $lock)
{
$this->write('Removing configuration and files');
$this->write('Removing files from recipe');
$this->removeFiles($config, $this->getRemovableFilesFromRecipeAndLock($recipe, $lock), $this->options->get('root-dir'));
}

Expand Down Expand Up @@ -107,7 +107,7 @@ private function copyFile(string $to, string $contents, bool $executable, array
@chmod($to, fileperms($to) | 0111);
}

$this->write(sprintf('Created <fg=green>"%s"</>', $this->path->relativize($to)));
$this->write(sprintf(' Created <fg=green>"%s"</>', $this->path->relativize($to)));

return $copiedFile;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ private function removeFile(string $to)
}

@unlink($to);
$this->write(sprintf('Removed <fg=green>"%s"</>', $this->path->relativize($to)));
$this->write(sprintf(' Removed <fg=green>"%s"</>', $this->path->relativize($to)));

if (0 === \count(glob(\dirname($to).'/*', GLOB_NOSORT))) {
@rmdir(\dirname($to));
Expand Down
4 changes: 2 additions & 2 deletions src/Configurator/EnvConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EnvConfigurator extends AbstractConfigurator
{
public function configure(Recipe $recipe, $vars, Lock $lock, array $options = [])
{
$this->write('Added environment variable defaults');
$this->write('Adding environment variable defaults');

$this->configureEnvDist($recipe, $vars, $options['force'] ?? false);
if (!file_exists($this->options->get('root-dir').'/.env.test')) {
Expand Down Expand Up @@ -145,7 +145,7 @@ private function unconfigurePhpUnit(Recipe $recipe, $vars)
continue;
}

$this->write(sprintf('Removed environment variables from %s', $file));
$this->write(sprintf('Removing environment variables from %s', $file));
file_put_contents($phpunit, $contents);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Configurator/GitignoreConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GitignoreConfigurator extends AbstractConfigurator
{
public function configure(Recipe $recipe, $vars, Lock $lock, array $options = [])
{
$this->write('Added entries to .gitignore');
$this->write('Adding entries to .gitignore');

$gitignore = $this->options->get('root-dir').'/.gitignore';
if (empty($options['force']) && $this->isFileMarked($recipe, $gitignore)) {
Expand Down Expand Up @@ -52,7 +52,7 @@ public function unconfigure(Recipe $recipe, $vars, Lock $lock)
return;
}

$this->write('Removed entries in .gitignore');
$this->write('Removing entries in .gitignore');
file_put_contents($file, ltrim($contents, "\r\n"));
}
}
4 changes: 2 additions & 2 deletions src/Configurator/MakefileConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MakefileConfigurator extends AbstractConfigurator
{
public function configure(Recipe $recipe, $definitions, Lock $lock, array $options = [])
{
$this->write('Added Makefile entries');
$this->write('Adding Makefile entries');

$makefile = $this->options->get('root-dir').'/Makefile';
if (empty($options['force']) && $this->isFileMarked($recipe, $makefile)) {
Expand Down Expand Up @@ -65,7 +65,7 @@ public function unconfigure(Recipe $recipe, $vars, Lock $lock)
return;
}

$this->write(sprintf('Removed Makefile entries from %s', $makefile));
$this->write(sprintf('Removing Makefile entries from %s', $makefile));
if (!trim($contents)) {
@unlink($makefile);
} else {
Expand Down

0 comments on commit 5f5078a

Please sign in to comment.