1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<?php
# $Id$
/**
* class to handle 'delete' in Cli
*/
class CliDelete extends Shell
{
/**
* Execution method always used for tasks
*/
public function execute()
{
if (empty($this->args)) {
return $this->__interactive();
}
if (!empty($this->args[0])) {
return $this->__handle($this->args[0]);
}
}
/**
* Interactive mode
*/
protected function __interactive()
{
$module = preg_replace('/Handler$/', '', $this->handler_to_use);
$module = strtolower($module);
$question = "Which $module do you want to delete?";
$address = $this->in($question);
$question = "Do you really want to delete '$address'?";
$create = $this->in($question, array('y','n'));
if ($create == 'y') {
return $this->__handle($address);
}
}
/**
* actually delete something
*
* @param string address to delete
*/
protected function __handle($address)
{
$handler = new $this->handler_to_use($this->new);
if (!$handler->init($address)) {
$this->err($handler->errormsg);
return 1;
}
if (!$handler->delete()) {
$this->err($handler->errormsg);
return 1;
}
$this->out($handler->infomsg);
return 0;
}
/**
* Display help contents
*
* @access public
*/
public function help()
{
$module = preg_replace('/Handler$/', '', $this->handler_to_use);
$module = strtolower($module);
$this->out(
"Usage:
postfixadmin-cli $module delete
Deletes $module in interactive mode.
- or -
postfixadmin-cli $module delete <address>
Deletes $module <address> in non-interactive mode.
"
);
$this->_stop(1);
}
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|