Added Flags to FS tasks (closes #344)

This commit is contained in:
thePanz
2017-02-07 23:28:10 +01:00
parent b36f90e80a
commit 33364f5e24
6 changed files with 88 additions and 17 deletions
+27
View File
@@ -46,6 +46,33 @@ abstract class AbstractFileTask extends AbstractTask
*/
abstract protected function getParameters();
/**
* Returns the default "flags".
*
* @return null|string
*/
protected function getDefaultFlags()
{
return null;
}
/**
* Returns the flags for the current command.
*
* @return string
*/
protected function getFlags()
{
$options = $this->getOptions();
$flags = $this->getDefaultFlags();
if (array_key_exists('flags', $options) && !empty($options['flags'])) {
$flags = trim($options['flags']);
}
return empty($flags) ? '' : $flags.' ';
}
/**
* Returns a file with the placeholders replaced
*
+9 -2
View File
@@ -28,7 +28,7 @@ class CopyTask extends AbstractFileTask
public function getDescription()
{
try {
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
return sprintf('[FS] Copy %s"%s" to "%s"', $this->getFlags(), $this->getFile('from'), $this->getFile('to'));
} catch (Exception $exception) {
return '[FS] Copy [missing parameters]';
}
@@ -39,7 +39,9 @@ class CopyTask extends AbstractFileTask
$copyFrom = $this->getFile('from');
$copyTo = $this->getFile('to');
$cmd = sprintf('cp -p %s %s', $copyFrom, $copyTo);
$flags = $this->getFlags();
$cmd = sprintf('cp %s"%s" "%s"', $flags, $copyFrom, $copyTo);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
@@ -51,4 +53,9 @@ class CopyTask extends AbstractFileTask
{
return ['from', 'to'];
}
protected function getDefaultFlags()
{
return '-p';
}
}
+9 -2
View File
@@ -28,7 +28,7 @@ class LinkTask extends AbstractFileTask
public function getDescription()
{
try {
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
return sprintf('[FS] Link %s"%s" to "%s"', $this->getFlags(), $this->getFile('from'), $this->getFile('to'));
} catch (Exception $exception) {
return '[FS] Link [missing parameters]';
}
@@ -39,7 +39,9 @@ class LinkTask extends AbstractFileTask
$linkFrom = $this->getFile('from');
$linkTo = $this->getFile('to');
$cmd = sprintf('ln -snf %s %s', $linkFrom, $linkTo);
$flags = $this->getFlags();
$cmd = sprintf('ln %s"%s" "%s"', $flags, $linkFrom, $linkTo);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
@@ -51,4 +53,9 @@ class LinkTask extends AbstractFileTask
{
return ['from', 'to'];
}
protected function getDefaultFlags()
{
return '-snf';
}
}
+3 -2
View File
@@ -28,7 +28,7 @@ class MoveTask extends AbstractFileTask
public function getDescription()
{
try {
return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
return sprintf('[FS] Move %s"%s" to "%s"', $this->getFlags(), $this->getFile('from'), $this->getFile('to'));
} catch (Exception $exception) {
return '[FS] Move [missing parameters]';
}
@@ -38,8 +38,9 @@ class MoveTask extends AbstractFileTask
{
$moveFrom = $this->getFile('from');
$moveTo = $this->getFile('to');
$flags = $this->getFlags();
$cmd = sprintf('mv %s %s', $moveFrom, $moveTo);
$cmd = sprintf('mv %s"%s" "%s"', $flags, $moveFrom, $moveTo);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
+3 -2
View File
@@ -28,7 +28,7 @@ class RemoveTask extends AbstractFileTask
public function getDescription()
{
try {
return sprintf('[FS] Remove "%s"', $this->getFile('file'));
return sprintf('[FS] Remove %s"%s"', $this->getFlags(), $this->getFile('file'));
} catch (Exception $exception) {
return '[FS] Remove [missing parameters]';
}
@@ -37,8 +37,9 @@ class RemoveTask extends AbstractFileTask
public function execute()
{
$file = $this->getFile('file');
$flags = $this->getFlags();
$cmd = sprintf('rm %s', $file);
$cmd = sprintf('rm %s"%s"', $flags, $file);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);