From 928c0e9b95c01c5772ae253d8c80f7c09a91feea Mon Sep 17 00:00:00 2001 From: David Bajger Date: Wed, 17 Jan 2024 12:50:55 +0100 Subject: [PATCH] Added version flag to launcher command. --- .../PhLCliCommandTest.class.st | 9 +++++++ src/PharoLauncher-CLI/PhLCliCommand.class.st | 26 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/PharoLauncher-CLI-Tests/PhLCliCommandTest.class.st b/src/PharoLauncher-CLI-Tests/PhLCliCommandTest.class.st index ca00d089..ca853efd 100644 --- a/src/PharoLauncher-CLI-Tests/PhLCliCommandTest.class.st +++ b/src/PharoLauncher-CLI-Tests/PhLCliCommandTest.class.st @@ -72,6 +72,15 @@ PhLCliCommandTest >> testExecuteLauncherCommandToPrintHelp [ ] +{ #category : #tests } +PhLCliCommandTest >> testExecuteLauncherCommandToPrintVersion [ + |expectedPrintout| + expectedPrintout := PhLAboutCommand new launcherVersion. + + self assertCommand: #('launcher' '--version') toPrintHelpWith: expectedPrintout. + +] + { #category : #tests } PhLCliCommandTest >> testExecuteOSShellCommand [ diff --git a/src/PharoLauncher-CLI/PhLCliCommand.class.st b/src/PharoLauncher-CLI/PhLCliCommand.class.st index 3b5a8b12..551ee4dc 100644 --- a/src/PharoLauncher-CLI/PhLCliCommand.class.st +++ b/src/PharoLauncher-CLI/PhLCliCommand.class.st @@ -49,9 +49,10 @@ PhLCliCommand class >> addDelimiterFlagTo: aCommandSpec [ { #category : #'command line - arguments' } PhLCliCommand class >> addLauncherFlagsTo: aCommandSpec [ - "No positionals on root spec class - use on subclasses e.g.: aCommandSpec addFlag: #someFlag + "Only version flag to launcher commmand. + Use on subclasses e.g.: aCommandSpec addFlag: #someFlag " + self addVersionFlagTo: aCommandSpec ] { #category : #'command line - arguments' } @@ -94,6 +95,14 @@ PhLCliCommand class >> addStonFlagTo: aCommandSpec [ description: 'Prints information in STON format.' ] +{ #category : #'command line - arguments' } +PhLCliCommand class >> addVersionFlagTo: aCommandSpec [ + + aCommandSpec + addFlag: #version + description: 'Prints version of the Pharo Launcher.' +] + { #category : #'command line - converting' } PhLCliCommand class >> asCliCommand [ ^ self newLauncherCommandSpec: #launcher @@ -157,6 +166,7 @@ PhLCliCommand class >> raiseMissingDelimiter [ PhLCliCommand >> basicExecute [ "should be implemented on all sub-classed commands that have business logic, otherwise will print just help" + self hasVersionFlag ifTrue: [ ^ self printVersion ]. self printHelp ] @@ -248,6 +258,12 @@ PhLCliCommand >> findLatestPharoStableVersionIn: aTemplateGroup [ ^ aTemplateGroup latestStableTemplate ] +{ #category : #'accessing arguments' } +PhLCliCommand >> hasVersionFlag [ + + ^ self hasFlag: #version +] + { #category : #accessing } PhLCliCommand >> imageRepository [ ^ self pharoLauncherModel imageRepository @@ -345,6 +361,12 @@ PhLCliCommand >> printSequence [ ^ true ] +{ #category : #printing } +PhLCliCommand >> printVersion [ + + self logInfoMessage: PhLAboutCommand new launcherVersion +] + { #category : #'accessing arguments' } PhLCliCommand >> rowMode [