Hoa central
Dependency.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Devtools\Bin;
38 
39 use Hoa\Console;
40 
50 {
56  protected $options = [
57  ['no-verbose', Console\GetOption::NO_ARGUMENT, 'V'],
58  ['only-library', Console\GetOption::NO_ARGUMENT, 'l'],
59  ['only-version', Console\GetOption::NO_ARGUMENT, 'v'],
60  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
61  ['help', Console\GetOption::NO_ARGUMENT, '?']
62  ];
63 
64 
65 
71  public function main()
72  {
73  $verbose = Console::isDirect(STDOUT);
74  $print = 'both';
75 
76  while (false !== $c = $this->getOption($v)) {
77  switch ($c) {
78  case 'V':
79  $verbose = false;
80 
81  break;
82 
83  case 'l':
84  $print = 'library';
85 
86  break;
87 
88  case 'v':
89  $print = 'version';
90 
91  break;
92 
93  case 'h':
94  case '?':
95  return $this->usage();
96 
97  case '__ambiguous':
98  $this->resolveOptionAmbiguity($v);
99 
100  break;
101  }
102  }
103 
104  $this->parser->listInputs($library);
105 
106  if (empty($library)) {
107  return $this->usage();
108  }
109 
110  $library = ucfirst(strtolower($library));
111  $path = 'hoa://Library/' . $library . '/composer.json';
112 
113  if (true === $verbose) {
114  echo 'Dependency for the library ', $library, ':', "\n";
115  }
116 
117  if (false === file_exists($path)) {
118  throw new Console\Exception(
119  'Not yet computed or the %s library does not exist.',
120  0,
121  $library
122  );
123  }
124 
125  $json = json_decode(file_get_contents($path), true);
126 
127  if (true === $verbose) {
128  $item = ' • ';
129  $separator = ' => ';
130  } else {
131  $item = '';
132  $separator = ' ';
133  }
134 
135  foreach ($json['require'] ?: [] as $dependency => $version) {
136  switch ($print) {
137  case 'both':
138  echo $item, $dependency, $separator, $version, "\n";
139 
140  break;
141 
142  case 'library':
143  echo $item, $dependency, "\n";
144 
145  break;
146 
147  case 'version':
148  echo $item, $version, "\n";
149 
150  break;
151  }
152  }
153 
154  return;
155  }
156 
162  public function usage()
163  {
164  echo
165  'Usage : devtools:dependency <options> library', "\n",
166  'Options :', "\n",
167  $this->makeUsageOptionsList([
168  'V' => 'No-verbose, i.e. be as quiet as possible, just print ' .
169  'essential informations.',
170  'l' => 'Print only the library name.',
171  'v' => 'Print only the version.',
172  'help' => 'This help.'
173  ]), "\n";
174 
175  return;
176  }
177 }
178 
179 __halt_compiler();
180 Manipulate dependencies of a library.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190
static isDirect($pipe)
Definition: Console.php:261