mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-08-28 18:18:57 +02:00
[Nostromo] Refactor FS Tasks flagging system
This commit is contained in:
@@ -48,33 +48,6 @@ 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
|
||||
*
|
||||
|
||||
@@ -28,11 +28,7 @@ class ChangeModeTask extends AbstractFileTask
|
||||
public function getDescription()
|
||||
{
|
||||
try {
|
||||
$description = sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
|
||||
if ($this->options['flags'] != null) {
|
||||
$description = sprintf('[FS] Change mode of "%s" to "%s" with flags "%s"', $this->getFile('file'), $this->options['mode'], $this->options['flags']);
|
||||
}
|
||||
return $description;
|
||||
return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
|
||||
} catch (Exception $exception) {
|
||||
return '[FS] Chmod [missing parameters]';
|
||||
}
|
||||
@@ -40,7 +36,11 @@ class ChangeModeTask extends AbstractFileTask
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$cmd = sprintf('chmod %s %s %s', $this->options['flags'], $this->options['mode'], $this->getFile('file'));
|
||||
$file = $this->getFile('file');
|
||||
$mode = $this->options['mode'];
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$cmd = sprintf('chmod %s %s "%s"', $flags, $mode, $file);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
|
||||
@@ -28,7 +28,7 @@ class CopyTask extends AbstractFileTask
|
||||
public function getDescription()
|
||||
{
|
||||
try {
|
||||
return sprintf('[FS] Copy %s"%s" to "%s"', $this->getFlags(), $this->getFile('from'), $this->getFile('to'));
|
||||
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
||||
} catch (Exception $exception) {
|
||||
return '[FS] Copy [missing parameters]';
|
||||
}
|
||||
@@ -38,10 +38,9 @@ class CopyTask extends AbstractFileTask
|
||||
{
|
||||
$copyFrom = $this->getFile('from');
|
||||
$copyTo = $this->getFile('to');
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$flags = $this->getFlags();
|
||||
|
||||
$cmd = sprintf('cp %s"%s" "%s"', $flags, $copyFrom, $copyTo);
|
||||
$cmd = sprintf('cp %s "%s" "%s"', $flags, $copyFrom, $copyTo);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@@ -51,11 +50,11 @@ class CopyTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['from', 'to'];
|
||||
return ['from', 'to', 'flags'];
|
||||
}
|
||||
|
||||
protected function getDefaultFlags()
|
||||
public function getDefaults()
|
||||
{
|
||||
return '-p';
|
||||
return ['flags' => '-p'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class LinkTask extends AbstractFileTask
|
||||
public function getDescription()
|
||||
{
|
||||
try {
|
||||
return sprintf('[FS] Link %s"%s" to "%s"', $this->getFlags(), $this->getFile('from'), $this->getFile('to'));
|
||||
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
||||
} catch (Exception $exception) {
|
||||
return '[FS] Link [missing parameters]';
|
||||
}
|
||||
@@ -38,10 +38,9 @@ class LinkTask extends AbstractFileTask
|
||||
{
|
||||
$linkFrom = $this->getFile('from');
|
||||
$linkTo = $this->getFile('to');
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$flags = $this->getFlags();
|
||||
|
||||
$cmd = sprintf('ln %s"%s" "%s"', $flags, $linkFrom, $linkTo);
|
||||
$cmd = sprintf('ln %s "%s" "%s"', $flags, $linkFrom, $linkTo);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@@ -51,11 +50,11 @@ class LinkTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['from', 'to'];
|
||||
return ['from', 'to', 'flags'];
|
||||
}
|
||||
|
||||
protected function getDefaultFlags()
|
||||
public function getDefaults()
|
||||
{
|
||||
return '-snf';
|
||||
return ['flags' => '-snf'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class MoveTask extends AbstractFileTask
|
||||
public function getDescription()
|
||||
{
|
||||
try {
|
||||
return sprintf('[FS] Move %s"%s" to "%s"', $this->getFlags(), $this->getFile('from'), $this->getFile('to'));
|
||||
return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
|
||||
} catch (Exception $exception) {
|
||||
return '[FS] Move [missing parameters]';
|
||||
}
|
||||
@@ -38,9 +38,9 @@ class MoveTask extends AbstractFileTask
|
||||
{
|
||||
$moveFrom = $this->getFile('from');
|
||||
$moveTo = $this->getFile('to');
|
||||
$flags = $this->getFlags();
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$cmd = sprintf('mv %s"%s" "%s"', $flags, $moveFrom, $moveTo);
|
||||
$cmd = sprintf('mv %s "%s" "%s"', $flags, $moveFrom, $moveTo);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@@ -50,6 +50,11 @@ class MoveTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['from', 'to'];
|
||||
return ['from', 'to', 'flags'];
|
||||
}
|
||||
|
||||
public function getDefaults()
|
||||
{
|
||||
return ['flags' => null];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class RemoveTask extends AbstractFileTask
|
||||
public function getDescription()
|
||||
{
|
||||
try {
|
||||
return sprintf('[FS] Remove %s"%s"', $this->getFlags(), $this->getFile('file'));
|
||||
return sprintf('[FS] Remove "%s"', $this->getFile('file'));
|
||||
} catch (Exception $exception) {
|
||||
return '[FS] Remove [missing parameters]';
|
||||
}
|
||||
@@ -37,9 +37,9 @@ class RemoveTask extends AbstractFileTask
|
||||
public function execute()
|
||||
{
|
||||
$file = $this->getFile('file');
|
||||
$flags = $this->getFlags();
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$cmd = sprintf('rm %s"%s"', $flags, $file);
|
||||
$cmd = sprintf('rm %s "%s"', $flags, $file);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@@ -49,6 +49,11 @@ class RemoveTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['file'];
|
||||
return ['file', 'flags'];
|
||||
}
|
||||
|
||||
public function getDefaults()
|
||||
{
|
||||
return ['flags' => null];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user