Skip to content

Commit

Permalink
Updating AclShell to use features of ConsoleOptionParser.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 99407e7 commit c3750d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
31 changes: 8 additions & 23 deletions cake/console/libs/acl.php
Expand Up @@ -106,29 +106,14 @@ public function startup() {
*
*/
public function main() {
$out = __('Available ACL commands:') . "\n";
$out .= "\t - create\n";
$out .= "\t - delete\n";
$out .= "\t - setParent\n";
$out .= "\t - getPath\n";
$out .= "\t - check\n";
$out .= "\t - grant\n";
$out .= "\t - deny\n";
$out .= "\t - inherit\n";
$out .= "\t - view\n";
$out .= "\t - initdb\n";
$out .= "\t - help\n\n";
$out .= __("For help, run the 'help' command. For help on a specific command, run 'help <command>'");
$this->out($out);
$this->out($this->OptionParser->help());
}

/**
* Creates an ARO/ACO node
*
*/
public function create() {
$this->_checkArgs(3, 'create');
$this->checkNodeType();
extract($this->__dataVars());

$class = ucfirst($this->args[0]);
Expand All @@ -144,13 +129,13 @@ public function create() {
if (is_string($data) && $data != '/') {
$data = array('alias' => $data);
} elseif (is_string($data)) {
$this->error(__('/ can not be used as an alias!'), __("\t/ is the root, please supply a sub alias"));
$this->error(__('/ can not be used as an alias!') . __(" / is the root, please supply a sub alias"));
}

$data['parent_id'] = $parent;
$this->Acl->{$class}->create();
if ($this->Acl->{$class}->save($data)) {
$this->out(sprintf(__("New %s '%s' created.\n"), $class, $this->args[2]), true);
$this->out(sprintf(__("<success>New %s</success> '%s' created."), $class, $this->args[2]), 2);
} else {
$this->err(sprintf(__("There was a problem creating a new %s '%s'."), $class, $this->args[2]));
}
Expand All @@ -161,17 +146,15 @@ public function create() {
*
*/
public function delete() {
$this->_checkArgs(2, 'delete');
$this->checkNodeType();
extract($this->__dataVars());

$identifier = $this->parseIdentifier($this->args[1]);
$nodeId = $this->_getNodeId($class, $identifier);

if (!$this->Acl->{$class}->delete($nodeId)) {
$this->error(__('Node Not Deleted'), sprintf(__('There was an error deleting the %s. Check that the node exists'), $class) . ".\n");
$this->error(__('Node Not Deleted') . sprintf(__('There was an error deleting the %s. Check that the node exists'), $class) . ".\n");
}
$this->out(sprintf(__('%s deleted'), $class) . ".\n", true);
$this->out(sprintf(__('<success>%s deleted.</success>'), $class), 2);
}

/**
Expand Down Expand Up @@ -396,9 +379,11 @@ public function getOptionParser() {
'type' => $type,
'parent' => array(
'help' => __('The node selector for the parent.'),
'required' => true
),
'alias' => array(
'help' => __('The alias to use for the newly created node.')
'help' => __('The alias to use for the newly created node.'),
'required' => true
)
)
)
Expand Down
2 changes: 2 additions & 0 deletions cake/console/libs/shell.php
Expand Up @@ -326,13 +326,15 @@ public function runCommand($command, $argv) {

$this->OptionParser = $this->getOptionParser();
list($this->params, $this->args) = $this->OptionParser->parse($argv, $command);
$this->command = $command;

if (($isTask || $isMethod || $isMain) && $command !== 'execute' ) {
$this->startup();
}
if (isset($this->params['help'])) {
return $this->out($this->OptionParser->help($command));
}

if ($isTask) {
$command = Inflector::camelize($command);
return $this->{$command}->runCommand('execute', $argv);
Expand Down

0 comments on commit c3750d1

Please sign in to comment.