Skip to content

Commit

Permalink
Add a command to update Template sources.
Browse files Browse the repository at this point in the history
Related to #652
  • Loading branch information
demarey committed Mar 1, 2024
1 parent 094cfb8 commit c122eb7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Class {
#name : #PhLTemplateUpdateCliCommandTest,
#superclass : #PhLTemplatesCliCommandTest,
#category : #'PharoLauncher-CLI-Tests'
}

{ #category : #tests }
PhLTemplateUpdateCliCommandTest >> testTemplateUpdateShouldSucceed [
| command workingDir |

workingDir := FileSystem memory root.
self launcherModel templateRepository: (PhLTemplateGroupRepository newFromGroups: #()).

PhLTemplateSources useLauncherCoreDir: workingDir during: [
PhLTemplateSources flush: #() in: workingDir / PhLTemplateSources sourcesFileName.
command := (context arguments: #('launcher' 'template' 'update')) command.
self assert: command pharoLauncherModel templateRepository roots size equals: 0.

command execute ].

"self assertSuccess."
self assert:( workingDir / 'sources.list') exists.
self assert: command pharoLauncherModel templateRepository roots size equals: 8
]
37 changes: 37 additions & 0 deletions src/PharoLauncher-CLI/PhLTemplateUpdateCliCommand.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"
I represent Pharo Template update sub-command invoked from cmd line of Pharo Launcher.
My responsibility is to update the list of templates from the official source.
"
Class {
#name : #PhLTemplateUpdateCliCommand,
#superclass : #PhLTemplateCliCommand,
#category : #'PharoLauncher-CLI-Commands'
}

{ #category : #'command line - converting' }
PhLTemplateUpdateCliCommand class >> asCliCommand [
^ self newLauncherCommandSpec: #update
]

{ #category : #'command execution' }
PhLTemplateUpdateCliCommand >> basicExecute [

self registerOnTemplateSourcesUpdate.
PhLPharoTemplateSources fromFile checkForUpdates.
self pharoLauncherModel resetTemplateRepository.
]

{ #category : #updating }
PhLTemplateUpdateCliCommand >> registerOnTemplateSourcesUpdate [

PhLPharoTemplateSources announcer weak
when: PhLSourcesFileUpdateAvailable
send: #updateTemplateSources
to: self.
]

{ #category : #updating }
PhLTemplateUpdateCliCommand >> updateTemplateSources [

PhLPharoTemplateSources fromFile updateSourcesFile
]
5 changes: 5 additions & 0 deletions src/PharoLauncher-CLI/PharoLauncherCLIModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ PharoLauncherCLIModel >> imageRepository: aPhLDirectoryBasedImageRepository [
imageRepository := aPhLDirectoryBasedImageRepository
]

{ #category : #initialization }
PharoLauncherCLIModel >> resetTemplateRepository [
templateRepository := nil
]

{ #category : #accessing }
PharoLauncherCLIModel >> templateRepository [
^ templateRepository
Expand Down
2 changes: 1 addition & 1 deletion src/PharoLauncher-Core/PhLPharoTemplateSources.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ PhLPharoTemplateSources class >> settingsOn: aBuilder [
{ #category : #accessing }
PhLPharoTemplateSources class >> sourcesFile [
"File with the list of default templates sources for Pharo Launcher"
^ self launcherCoreDir / 'sources.list'
^ self launcherCoreDir / self sourcesFileName
]

{ #category : #accessing }
Expand Down
18 changes: 17 additions & 1 deletion src/PharoLauncher-Core/PhLTemplateSources.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ PhLTemplateSources class >> settingsOn: aBuilder [
, 'NOTE: This path might need to escape some whitespace characters.' translated.
]

{ #category : #accessing }
PhLTemplateSources class >> sourcesFileName [
"Name of the file with the list of default templates sources for Pharo Launcher"
^ 'sources.list'
]

{ #category : #accessing }
PhLTemplateSources class >> useLauncherCoreDir: aDirectory during: aBlock [

| oldLauncherCoreDir |
oldLauncherCoreDir := LauncherCoreDir.
[ LauncherCoreDir := aDirectory.
aBlock value ]
ensure: [ LauncherCoreDir := oldLauncherCoreDir ]
]

{ #category : #'instance creation' }
PhLTemplateSources class >> withFile: aSourcesFile [
^ self new
Expand All @@ -111,7 +127,7 @@ PhLTemplateSources class >> withFile: aSourcesFile [
{ #category : #'instance creation' }
PhLTemplateSources class >> withTemplateList: aListOfPhLTemplateSource [
| file |
file := FileSystem memory / 'sources.list'.
file := FileSystem memory / self sourcesFileName.
self flush: aListOfPhLTemplateSource in: file.
^ self withFile: file
]
Expand Down

0 comments on commit c122eb7

Please sign in to comment.