3
3
namespace ShipMonk \ComposerDependencyAnalyser ;
4
4
5
5
use Composer \Autoload \ClassLoader ;
6
+ use Composer \InstalledVersions ;
7
+ use OutOfBoundsException ;
6
8
use ShipMonk \ComposerDependencyAnalyser \Config \Configuration ;
7
9
use ShipMonk \ComposerDependencyAnalyser \Config \ErrorType ;
10
+ use ShipMonk \ComposerDependencyAnalyser \Exception \AbortException ;
8
11
use ShipMonk \ComposerDependencyAnalyser \Exception \InvalidCliException ;
9
12
use ShipMonk \ComposerDependencyAnalyser \Exception \InvalidConfigException ;
10
13
use ShipMonk \ComposerDependencyAnalyser \Exception \InvalidPathException ;
11
14
use ShipMonk \ComposerDependencyAnalyser \Result \ConsoleFormatter ;
12
15
use ShipMonk \ComposerDependencyAnalyser \Result \JunitFormatter ;
13
16
use ShipMonk \ComposerDependencyAnalyser \Result \ResultFormatter ;
14
17
use Throwable ;
18
+ use function class_exists ;
15
19
use function count ;
16
20
use function get_class ;
17
21
use function is_file ;
@@ -28,6 +32,7 @@ class Initializer
28
32
vendor/bin/composer-dependency-analyser
29
33
30
34
Options:
35
+ --version Print analyser version.
31
36
--help Print this help text and exit.
32
37
--verbose Print more usage examples
33
38
--show-all-usages Removes the limit of showing only few usages
@@ -220,6 +225,7 @@ public function initComposerClassLoaders(): array
220
225
221
226
/**
222
227
* @param list<string> $argv
228
+ * @throws AbortException
223
229
* @throws InvalidCliException
224
230
*/
225
231
public function initCliOptions (string $ cwd , array $ argv ): CliOptions
@@ -228,7 +234,12 @@ public function initCliOptions(string $cwd, array $argv): CliOptions
228
234
229
235
if ($ cliOptions ->help !== null ) {
230
236
$ this ->stdOutPrinter ->printLine (self ::$ help );
231
- throw new InvalidCliException ('' ); // just exit
237
+ throw new AbortException ();
238
+ }
239
+
240
+ if ($ cliOptions ->version !== null ) {
241
+ $ this ->stdOutPrinter ->printLine ($ this ->deduceVersion ());
242
+ throw new AbortException ();
232
243
}
233
244
234
245
return $ cliOptions ;
@@ -256,4 +267,19 @@ public function initFormatter(CliOptions $options): ResultFormatter
256
267
throw new InvalidConfigException ("Invalid format option provided, allowed are 'console' or 'junit'. " );
257
268
}
258
269
270
+ private function deduceVersion (): string
271
+ {
272
+ try {
273
+ /** @throws OutOfBoundsException */
274
+ $ version = class_exists (InstalledVersions::class)
275
+ ? InstalledVersions::getPrettyVersion ('shipmonk/composer-dependency-analyser ' )
276
+ : 'unknown ' ;
277
+
278
+ } catch (OutOfBoundsException $ e ) {
279
+ $ version = 'not found ' ;
280
+ }
281
+
282
+ return "Version: $ version " ;
283
+ }
284
+
259
285
}
0 commit comments