Hoa central
Clean.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Test\Bin;
38 
39 use Hoa\Console;
40 use Hoa\File;
41 
51 {
57  protected $options = [
58  ['all', Console\GetOption::NO_ARGUMENT, 'a'],
59  ['libraries', Console\GetOption::REQUIRED_ARGUMENT, 'l'],
60  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
61  ['help', Console\GetOption::NO_ARGUMENT, '?']
62  ];
63 
64 
65 
71  public function main()
72  {
73  $libraries = [];
74 
75  while (false !== $c = $this->getOption($v)) {
76  switch ($c) {
77  case 'a':
78  $iterator = new File\Finder();
79  $iterator->in(resolve('hoa://Library/', true, true))
80  ->directories()
81  ->maxDepth(1);
82 
83  foreach ($iterator as $fileinfo) {
84  $libraryName = $fileinfo->getBasename();
85  $pathname = resolve('hoa://Library/' . $libraryName);
86  $automaticTests = $pathname . DS . 'Test' . DS .
87  'Praspel' . DS;
88 
89  if (is_dir($automaticTests)) {
90  $libraries[] = $automaticTests;
91  }
92  }
93 
94  if (empty($libraries)) {
95  echo 'Already clean.';
96 
97  return;
98  }
99 
100  break;
101 
102  case 'l':
103  foreach ($this->parser->parseSpecialValue($v) as $library) {
104  $libraryName = ucfirst(strtolower($library));
105  $pathname = resolve('hoa://Library/' . $libraryName);
106  $automaticTests = $pathname . DS . 'Test' . DS .
107  'Praspel' . DS;
108 
109  if (is_dir($automaticTests)) {
110  $libraries[] = $automaticTests;
111  }
112  }
113 
114  if (empty($libraries)) {
115  echo 'Already clean.';
116 
117  return;
118  }
119 
120  break;
121 
122  case '__ambiguous':
123  $this->resolveOptionAmbiguity($v);
124 
125  break;
126 
127  case 'h':
128  case '?':
129  default:
130  return $this->usage();
131  }
132  }
133 
134  if (empty($libraries)) {
135  return $this->usage();
136  }
137 
138  foreach ($libraries as $path) {
139  $status =
140  'Clean ' .
141  (40 < strlen($path)
142  ? '…' . substr($path, -39)
143  : $path);
144  echo ' ⌛ ' , $status;
145 
146  $directory = new File\Directory($path);
147 
148  if (false === $directory->delete()) {
149  echo
150  ' ', Console\Chrome\Text::colorize('✖︎', 'foreground(red)'),
151  ' ', $status, "\n";
152  } else {
153  Console\Cursor::clear('↔');
154  echo
155  ' ', Console\Chrome\Text::colorize('✔︎', 'foreground(green)'),
156  ' ', $status, "\n";
157  }
158 
159  $directory->close();
160  }
161 
162  return;
163  }
164 
170  public function usage()
171  {
172  echo
173  'Usage : test:clean <options>', "\n",
174  'Options :', "\n",
175  $this->makeUsageOptionsList([
176  'a' => 'Clean all generated tests of all libraries.',
177  'l' => 'Clean all generated tests of some libraries.',
178  'help' => 'This help.'
179  ]), "\n";
180 
181  return;
182  }
183 }
184 
185 __halt_compiler();
186 Clean generated tests.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
static clear($parts= 'all')
Definition: Cursor.php:271
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190
static colorize($text, $attributesBefore, $attributesAfter= 'normal')
Definition: Text.php:83