-fixed bug in setup
-added availableOptions to commands -a few changes to plugins interaction
Esse commit está contido em:
@@ -55,7 +55,7 @@ class En implements l10n{
|
||||
$this->messages['dbDriverNotFound'] = Mind::message("Theos: Database Driver not found", '[Fail]', false);
|
||||
$this->messages['missingParameter'] = Mind::message("API: Missing argument: %s", '[Fail]', false);
|
||||
$this->messages['done'] = Mind::message("API: Done\n", '[Ok]', false);
|
||||
$this->messages['invalidOptionValue'] = Mind::message("API: %s is not a valid option for %s", '[Fail]', false);
|
||||
$this->messages['invalidOptionValue'] = Mind::message("API: '%s' is not a valid option for '%s'", '[Fail]', false);
|
||||
$this->messages['runnintPHPUnit'] = "Please wait...running PHPUnit...\n";
|
||||
$this->messages['phpunitNotFound'] = "You must specify where to find phpUnit classes\n".
|
||||
"You can configure it on mind3rd/env/mind.ini ini file\n".
|
||||
|
||||
@@ -63,7 +63,7 @@ class pt implements l10n{
|
||||
$this->messages['dbDriverNotFound'] = Mind::message("Theos: Database Driver não encontrado", '[Fail]', false);
|
||||
$this->messages['missingParameter'] = Mind::message("API: Argumento faltando: %s", '[Fail]', false);
|
||||
$this->messages['done'] = Mind::message("API: Pronto\n", '[Ok]', false);
|
||||
$this->messages['invalidOptionValue'] = Mind::message("API: %s não é uma opção válida para %s", '[Fail]', false);
|
||||
$this->messages['invalidOptionValue'] = Mind::message("API: '%s' não é uma opção válida para '%s'", '[Fail]', false);
|
||||
$this->messages['runnintPHPUnit'] = "Aguarde...executando testes unitários...\n";
|
||||
$this->messages['phpunitNotFound'] = "Especifique onde encontram-se as classes do PHPUnit\n".
|
||||
"Você pode configurar isto em mind3rd/env/mind.ini ini file\n".
|
||||
|
||||
@@ -11,14 +11,15 @@
|
||||
*/
|
||||
class MindCommand extends Symfony\Component\Console\Command\Command
|
||||
{
|
||||
private $restrict = true;
|
||||
private $fileName = null;
|
||||
private $requiredArguments = Array();
|
||||
private $optionalArguments = Array();
|
||||
private $requiredOptions = Array();
|
||||
private $optionalOptions = Array();
|
||||
private $commandFlags = Array();
|
||||
public $answers = Array();
|
||||
private $restrict = true;
|
||||
private $fileName = null;
|
||||
private $requiredArguments = Array();
|
||||
private $optionalArguments = Array();
|
||||
private $requiredOptions = Array();
|
||||
private $optionalOptions = Array();
|
||||
private $commandFlags = Array();
|
||||
public $answers = Array();
|
||||
public $commandAvailableOptions = Array();
|
||||
|
||||
public function init()
|
||||
{
|
||||
@@ -37,6 +38,19 @@ class MindCommand extends Symfony\Component\Console\Command\Command
|
||||
$this->optionalOptions,
|
||||
$this->commandFlags);
|
||||
|
||||
$helpDetails= "\n";
|
||||
$avOptsStr= Array();
|
||||
foreach($this->commandAvailableOptions as $k=>$avOpts)
|
||||
{
|
||||
if($avOpts)
|
||||
{
|
||||
$avOptsStr[]= " ->".$k."\n ".implode(', ', $avOpts);
|
||||
}
|
||||
}
|
||||
if(sizeof($avOptsStr)>0)
|
||||
$helpDetails.= "\nAvailables options:\n".implode("\n", $avOptsStr);
|
||||
$this->setHelp($this->getHelp().$helpDetails);
|
||||
|
||||
$this->setDefinition($definition);
|
||||
}
|
||||
|
||||
@@ -112,45 +126,75 @@ class MindCommand extends Symfony\Component\Console\Command\Command
|
||||
return $this->answers[$name];
|
||||
}
|
||||
|
||||
public function addRequiredArgument($argName, $agDescription='')
|
||||
public function addRequiredArgument($argName,
|
||||
$description='',
|
||||
$availableOptions=null)
|
||||
{
|
||||
$this->requiredArguments[]= new InputArgument($argName,
|
||||
if($availableOptions)
|
||||
$description.= "(".implode(', ', $availableOptions).")";
|
||||
$this->requiredArguments[$argName]= new InputArgument($argName,
|
||||
InputArgument::REQUIRED,
|
||||
$agDescription);
|
||||
$description);
|
||||
$this->commandAvailableOptions[$argName]= $availableOptions;
|
||||
return $this;
|
||||
}
|
||||
public function addOptionalArgument($argName, $agDescription='')
|
||||
public function addOptionalArgument($argName,
|
||||
$description='',
|
||||
$availableOptions=null)
|
||||
{
|
||||
$this->optionalArguments[]= new InputArgument($argName,
|
||||
if($availableOptions)
|
||||
$description.= "(".implode(', ', $availableOptions).")";
|
||||
$this->optionalArguments[$argName]= new InputArgument($argName,
|
||||
InputArgument::OPTIONAL,
|
||||
$agDescription);
|
||||
$description);
|
||||
$this->commandAvailableOptions[$argName]= $availableOptions;
|
||||
return $this;
|
||||
}
|
||||
public function addRequiredOption($name, $shortCut=null, $description='', $default=null)
|
||||
public function addRequiredOption($argName,
|
||||
$shortCut=null,
|
||||
$description='',
|
||||
$default=null,
|
||||
$availableOptions=null)
|
||||
{
|
||||
$this->requiredOptions[]= new InputOption($name,
|
||||
if($availableOptions)
|
||||
$description.= "(".implode(', ', $availableOptions).")";
|
||||
$this->requiredOptions[$argName]= new InputOption($argName,
|
||||
$shortCut,
|
||||
InputOption::PARAMETER_REQUIRED,
|
||||
$description,
|
||||
$default);
|
||||
$this->commandAvailableOptions[$argName]= $availableOptions;
|
||||
return $this;
|
||||
}
|
||||
public function addOptionalOption($name, $shortCut=null, $description='', $default=null)
|
||||
public function addOptionalOption($argName,
|
||||
$shortCut=null,
|
||||
$description='',
|
||||
$default=null,
|
||||
$availableOptions=null)
|
||||
{
|
||||
$this->optionalOptions[]= new InputOption($name,
|
||||
if($availableOptions)
|
||||
$description.= "(".implode(', ', $availableOptions).")";
|
||||
$this->optionalOptions[$argName]= new InputOption($argName,
|
||||
$shortCut,
|
||||
InputOption::PARAMETER_OPTIONAL,
|
||||
$description,
|
||||
$default);
|
||||
$this->commandAvailableOptions[$argName]= $availableOptions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addFlag($name, $shortCut=null, $description='')
|
||||
public function addFlag($argName,
|
||||
$shortCut=null,
|
||||
$description='',
|
||||
$availableOptions=null)
|
||||
{
|
||||
$this->commandFlags[]= new InputOption($name,
|
||||
if($availableOptions)
|
||||
$description.= "(".implode(', ', $availableOptions).")";
|
||||
$this->commandFlags[$argName]= new InputOption($argName,
|
||||
$shortCut,
|
||||
InputOption::PARAMETER_NONE,
|
||||
$description);
|
||||
$this->commandAvailableOptions[$argName]= $availableOptions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -361,12 +405,27 @@ class MindCommand extends Symfony\Component\Console\Command\Command
|
||||
|
||||
$this->runPlugins('before');
|
||||
|
||||
/*echo "\n\n";
|
||||
print_r($this->commandAvailableOptions);
|
||||
echo "\n\n";*/
|
||||
|
||||
foreach($this->commandAvailableOptions as $k=>$avOpts)
|
||||
{
|
||||
if($avOpts && !in_array(strtolower($this->$k),
|
||||
array_map('strtolower', $avOpts)))
|
||||
{
|
||||
Mind::write('invalidOptionValue', true, $this->$k, $k);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// yea, I know it looks a bit crazy!
|
||||
if(is_string($this->commandAction))
|
||||
$this->{$this->commandAction}();
|
||||
else
|
||||
call_user_func($this->commandAction, $this);
|
||||
|
||||
|
||||
$this->runPlugins('after');
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,40 @@
|
||||
public $description;
|
||||
public $links= Array();
|
||||
|
||||
public function listPlugins($echoes)
|
||||
{
|
||||
if($echoes)
|
||||
{
|
||||
$col1= 34;
|
||||
$col2= 25;
|
||||
$col34= 8;
|
||||
$header = "|".str_pad("Plugin", $col1, " ", STR_PAD_BOTH);
|
||||
$header.= "|".str_pad("Trigger", $col2, " ", STR_PAD_BOTH);
|
||||
$header.= "|".str_pad("Event", $col34, " ", STR_PAD_BOTH);
|
||||
$header.= "|".str_pad("Active", $col34, " ", STR_PAD_BOTH)."|\n";
|
||||
$line= "+".str_pad("", 78, '-')."+";
|
||||
$echoes= $line;
|
||||
$echoes.=$header;
|
||||
$echoes.=$line;
|
||||
foreach(Mind::$pluginList as $program)
|
||||
{
|
||||
foreach($program as $event)
|
||||
{
|
||||
foreach($event as $plugin)
|
||||
{
|
||||
$echoes.="|".str_pad($plugin->name, $col1, ' ', STR_PAD_RIGHT);
|
||||
$echoes.="|".str_pad($plugin->trigger, $col2, ' ', STR_PAD_RIGHT);
|
||||
$echoes.="|".str_pad($plugin->event, $col34, ' ', STR_PAD_RIGHT);
|
||||
$echoes.="|".str_pad(($plugin->active? 'Y': 'N'), $col34, ' ', STR_PAD_BOTH)."|\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$echoes.=$line;
|
||||
echo $echoes;
|
||||
}
|
||||
return Mind::$pluginList;
|
||||
}
|
||||
|
||||
public function setTrigger($trg)
|
||||
{
|
||||
$this->trigger= $trg;
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setTrigger('info');
|
||||
$this->setEvent('after');
|
||||
$this->setTrigger('test');
|
||||
$this->setEvent('before');
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
// change this flag to true and execute the test program
|
||||
// to see this plugin running
|
||||
public $active= false;
|
||||
public $active= true;
|
||||
|
||||
public function run()
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ EOT
|
||||
Mind::write('projectAlreadyExists', true, $this->argName);
|
||||
return false;
|
||||
}
|
||||
if(!@mkdir($this->projectfile))
|
||||
if(!file_exists($this->projectfile) && !@mkdir($this->projectfile))
|
||||
{
|
||||
Mind::message("Couldn create the project", "[Fail]");
|
||||
echo "I had no rights to write in the mind3rd/projects directory!\n";
|
||||
@@ -131,15 +131,12 @@ EOT
|
||||
)";
|
||||
|
||||
$db->execute($qr_vsProj);
|
||||
$db->execute("COMMIT");
|
||||
|
||||
if(!file_exists($this->projectfile) && !file_exists($iniSource))
|
||||
if(!file_exists($iniSource))
|
||||
{
|
||||
Mind::copyDir(Mind::$modelsDir.'mind/', $this->projectfile);
|
||||
chmod($this->projectfile, 0777);
|
||||
|
||||
Mind::write('projectCreated', true, $this->argName);
|
||||
|
||||
$ini= file_get_contents($iniSource);
|
||||
$ini= str_replace('<idiom>',
|
||||
$cP['default_human_language'],
|
||||
@@ -156,6 +153,9 @@ EOT
|
||||
$ini);
|
||||
}
|
||||
|
||||
Mind::write('projectCreated', true, $this->argName);
|
||||
$db->execute("COMMIT");
|
||||
|
||||
Mind::openProject(Array('pk_project'=>$key,
|
||||
'name'=>$this->argName));
|
||||
break;
|
||||
|
||||
@@ -19,8 +19,15 @@
|
||||
EOT
|
||||
);
|
||||
|
||||
$this->addRequiredArgument('what', 'What to how');
|
||||
$this->addOptionalArgument('extra', 'Extra information to be used');
|
||||
$this->addRequiredArgument('what',
|
||||
'What to show',
|
||||
Array('projects',
|
||||
'users',
|
||||
'entities',
|
||||
'relations',
|
||||
'version',
|
||||
'plugins'));
|
||||
$this->addOptionalArgument('extra', 'Any extra information to be used');
|
||||
$this->addFlag('detailed', '-d', 'Show detailed data');
|
||||
|
||||
$this->init();
|
||||
@@ -128,6 +135,9 @@ EOT
|
||||
echo "Current version: ".Mind::$currentProject['version']."\n";
|
||||
}
|
||||
break;
|
||||
case 'plugins':
|
||||
MindPlugin::listPlugins($_REQ['env']!='http');
|
||||
break;
|
||||
default:
|
||||
Mind::write('invalidOption', true, $this->what);
|
||||
return false;
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
* Your class will receive a property for each parameter, which can be accessed
|
||||
* by its argument name(in this example, 'firstArgument'.
|
||||
*/
|
||||
$this->addRequiredArgument('firstArgument', 'first, and required argument');
|
||||
$this->addRequiredArgument('firstArgument',
|
||||
'first, and required argument',
|
||||
Array('X', 'Y', 'Z'));
|
||||
//$this->addOptionalArgument('secondArgument', 'This is the second and optional argument');
|
||||
//$this->addRequiredOption('user', '-u', 'The user who will be passed for any reason', 'root');
|
||||
//$this->addOptionalOption('detailed', '-d', 'Should perform its action detailed?', null);
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário