You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CliDelete.php 1.8KB

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