You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-08-09 05:02:44 +03:00
model/CliEdit.php:
- new class for CLI add and edit - based on AddTask, but big parts of __interactive()) are rewritten to: - use $struct for the user interface (which means it will automatically adopt to changes in the *Handler classes) - check all entered data instantly. If an invalid value was entered, ask again to give the user a chance to enter valid data. - CliEdit already replaces all AddTask classes (interactive mode works, commandline parameter mode not implementated yet) - will also replace all EditTask classes in the future scripts/shells/shell.php - loadTasks(): for add, use new CliEdit instead of AddTask class - in(): - print additional empty line if $prompt is not empty - print error message when invalid option is chosen - always return raw $in to avoid '0' vs. ''. vs NULL problems git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1437 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
@@ -207,7 +207,10 @@ if ( empty($this->params['q'] ) ) {
|
||||
$taskClass = Inflector::camelize($taskName.'Task');
|
||||
$taskKey = Inflector::underscore($taskClass);
|
||||
|
||||
if (!class_exists($taskClass)) {
|
||||
if ($taskName == 'Add') {
|
||||
$taskClass = 'CliEdit';
|
||||
|
||||
} elseif (!class_exists($taskClass)) {
|
||||
foreach ($this->Dispatch->shellPaths as $path) {
|
||||
$taskPath = $path . 'tasks' . DS . $task.'.php';
|
||||
if (file_exists($taskPath)) {
|
||||
@@ -223,7 +226,11 @@ if ( empty($this->params['q'] ) ) {
|
||||
} else {
|
||||
$this->{$taskName} = new $taskClass($this->Dispatch);
|
||||
}
|
||||
|
||||
|
||||
if ($taskName == 'Add') {
|
||||
$this->{$taskName}->handler_to_use = ucfirst($this->shell) . 'Handler';
|
||||
$this->{$taskName}->new = 1;
|
||||
}
|
||||
|
||||
if (!isset($this->{$taskName})) {
|
||||
$this->err("Task '".$taskName."' could not be loaded");
|
||||
@@ -247,6 +254,7 @@ if ( empty($this->params['q'] ) ) {
|
||||
if (!$this->interactive) {
|
||||
return $default;
|
||||
}
|
||||
if ($prompt != '') $this->out("");
|
||||
$in = $this->Dispatch->getInput($prompt, $options, $default);
|
||||
|
||||
if ($options && is_string($options)) {
|
||||
@@ -260,12 +268,12 @@ if ( empty($this->params['q'] ) ) {
|
||||
}
|
||||
if (is_array($options)) {
|
||||
while ($in == '' || ($in && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
|
||||
$this->err("Invalid input"); # TODO: make translateable
|
||||
$in = $this->Dispatch->getInput($prompt, $options, $default);
|
||||
}
|
||||
}
|
||||
if ($in) {
|
||||
return $in;
|
||||
}
|
||||
|
||||
return $in;
|
||||
}
|
||||
/**
|
||||
* Outputs to the stdout filehandle.
|
||||
|
Reference in New Issue
Block a user