Skip to content

Commit

Permalink
Mark default value in template and category listing. Fixes pharo-proj…
Browse files Browse the repository at this point in the history
  • Loading branch information
demarey committed Jan 31, 2024
1 parent 67f146b commit 9111e06
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 47 deletions.
58 changes: 40 additions & 18 deletions src/PharoLauncher-CLI-Tests/ConsoleListFormatterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ConsoleListFormatterTest >> setUp [
command cliFormatter: formatter.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testAttributeValuesFrom [

formatter attributeValueBlocks: {
Expand All @@ -31,14 +31,14 @@ ConsoleListFormatterTest >> testAttributeValuesFrom [
self assert: (formatter attributeValuesFrom: 2) equals: #('2' '4' '8').
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testFormatterAccessors [

formatter attributeLabels: #().

]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testGetColumnWidthsFrom [
formatter attributeLabels: #('1234567890' 'x' 'x').
formatter attributeValueBlocks:
Expand All @@ -61,7 +61,7 @@ ConsoleListFormatterTest >> testGetMaxPrintStringWidthForPrintBlock [
self assert: size equals: 5.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintAttributeHeadersBy [
formatter
printAttributeHeaders: #('label1' 'label2' 'label3')
Expand All @@ -78,7 +78,7 @@ ConsoleListFormatterTest >> testPrintAttributeHeadersBy [
newLine ])
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintAttributeHeadersByNoSequence [
"formatted header should not contain sequence column"

Expand All @@ -99,7 +99,7 @@ ConsoleListFormatterTest >> testPrintAttributeHeadersByNoSequence [
newLine ])
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintAttributeRowsBy [

|expectedString|
Expand All @@ -118,7 +118,7 @@ ConsoleListFormatterTest >> testPrintAttributeRowsBy [
self assert: formatter outStream contents equals: expectedString.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintAttributeTable [

|expectedString|
Expand All @@ -140,7 +140,29 @@ ConsoleListFormatterTest >> testPrintAttributeTable [

]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintAttributeTableWithDefaultValue [

|expectedString|
formatter attributeLabels: #('Value' 'Squared' 'Raised to 3').
formatter attributeValueBlocks: { [:a |a asWords ]. [:a |a squared asWords ]. [:a |(a **3) asWords ] }.
formatter domainObjects: #(1 2 3) defaultValue: 2.
formatter printAttributeTable.

expectedString := String streamContents: [:aStream |
aStream
nextPutAll: '# *Value*Squared*Raised to 3 '; newLine;
nextPutAll: '---*-----*-------*------------'; newLine;
nextPutAll: ' 1 *one *one *one '; newLine;
nextPutAll: '*2 *two *four *eight '; newLine;
nextPutAll: ' 3 *three*nine *twenty-seven'; newLine
].

self assert: formatter outStream contents equals: expectedString.

]

{ #category : #tests }
ConsoleListFormatterTest >> testPrintCellWidth [

formatter printCell: 'value' width: 10.
Expand All @@ -150,21 +172,21 @@ ConsoleListFormatterTest >> testPrintCellWidth [
self assert: command outStream contents equals: 'value'.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintDelimiter [

formatter printDelimiter.
self assert: command outStream contents equals: command delimiter.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintHeaderLinesBy [

formatter printHeaderLinesBy: #(1 1 2 2).
self assert: command outStream contents equals: (String streamContents: [:aStream | aStream nextPutAll: '--*-*-*--*--'; newLine]).
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintHeaderLinesByNoSequence [

"formatted header line should not contain sequence column"
Expand All @@ -173,14 +195,14 @@ ConsoleListFormatterTest >> testPrintHeaderLinesByNoSequence [
self assert: command outStream contents equals: (String streamContents: [:aStream | aStream nextPutAll: '--*--'; newLine]).
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintLineSized [

formatter printLineSized: 5.
self assert: command outStream contents equals: '-----'.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintListAsSton [

| domainObjects deserialized |
Expand All @@ -194,7 +216,7 @@ ConsoleListFormatterTest >> testPrintListAsSton [
self assert: deserialized first class equals: PhLImageMock.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintListShouldPrintAttributesTableWhenStonAndRowModesDisabled [
| tableModeString |
formatter attributeLabels: #('Value' 'Squared' 'Raised to 3').
Expand All @@ -213,7 +235,7 @@ ConsoleListFormatterTest >> testPrintListShouldPrintAttributesTableWhenStonAndRo
self assert: formatter outStream contents equals: tableModeString
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintListShouldPrintAttributesTableWhenStonDisabledAndRowModeEnabled [

| rowModeString |
Expand All @@ -235,7 +257,7 @@ ConsoleListFormatterTest >> testPrintListShouldPrintAttributesTableWhenStonDisab
self assert: formatter outStream contents equals: rowModeString
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintOneAttrPerRow [
|expectedString|
formatter attributeLabels: #('Value' 'Squared' 'Raised to 3').
Expand All @@ -262,7 +284,7 @@ ConsoleListFormatterTest >> testPrintOneAttrPerRow [
self assert: formatter outStream contents equals: expectedString.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintOneAttrPerRowNoSequence [
|expectedString|
"row output should not contain sequence number"
Expand All @@ -281,7 +303,7 @@ ConsoleListFormatterTest >> testPrintOneAttrPerRowNoSequence [
self assert: formatter outStream contents equals: expectedString.
]

{ #category : #test }
{ #category : #tests }
ConsoleListFormatterTest >> testPrintRowValuesBy [
formatter printRowValues: #('One' 'Two' 'Three') by: #(5 3 5).

Expand Down
43 changes: 39 additions & 4 deletions src/PharoLauncher-CLI/ConsoleListFormatter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ ConsoleListFormatter >> domainObjects [
{ #category : #'accessing - public' }
ConsoleListFormatter >> domainObjects: anObjects [

domainObjects := anObjects
domainObjects := anObjects.
defaultValue := nil.
]

{ #category : #'accessing - public' }
ConsoleListFormatter >> domainObjects: someObjects defaultValue: anObject [

domainObjects := someObjects.
defaultValue := anObject.
]

{ #category : #private }
Expand All @@ -144,6 +152,24 @@ ConsoleListFormatter >> getMaxPrintStringWidthFor: someObjects printBlock: print
max
]

{ #category : #testing }
ConsoleListFormatter >> hasDefaultValue [

^ defaultValue notNil
]

{ #category : #private }
ConsoleListFormatter >> indexColumnDefaultSize [
^ 2
]

{ #category : #private }
ConsoleListFormatter >> indexColumnSize [
^ self hasDefaultValue
ifTrue: [ self indexColumnDefaultSize + 1 ]
ifFalse: [ self indexColumnDefaultSize ]
]

{ #category : #'accessing - command' }
ConsoleListFormatter >> outStream [

Expand Down Expand Up @@ -174,7 +200,7 @@ ConsoleListFormatter >> printAttributeHeaders: labels by: columnWidths [

"print sequence nr. eventually"
self printSequence ifTrue: [
self printCell: '#' width: 2.
self printCell: '#' width: self indexColumnSize.
self printDelimiter
].
self printRowValues: labels by: columnWidths.
Expand All @@ -185,7 +211,8 @@ ConsoleListFormatter >> printAttributeHeaders: labels by: columnWidths [
ConsoleListFormatter >> printAttributeRows: someObjects by: columnWidths [

someObjects withIndexDo: [:listedObject :idx|
self printCell: idx asString width: 2.
self hasDefaultValue ifTrue: [ self printDefaultValueMark: listedObject ].
self printCell: idx asString width: self indexColumnDefaultSize.
self printDelimiter.
self printRowValues: (self attributeValuesFrom: listedObject) by: columnWidths
]
Expand All @@ -209,6 +236,14 @@ ConsoleListFormatter >> printCell: aString width: widthSize [

]

{ #category : #private }
ConsoleListFormatter >> printDefaultValueMark: listedObject [

self outStream nextPut: (listedObject == defaultValue
ifTrue: [ $* ]
ifFalse: [ Character space ])
]

{ #category : #private }
ConsoleListFormatter >> printDelimiter [

Expand All @@ -220,7 +255,7 @@ ConsoleListFormatter >> printHeaderLinesBy: columnWidths [
"print header line"

self printSequence ifTrue: [
self printLineSized: 2.
self printLineSized: self indexColumnSize.
self printDelimiter.
].
columnWidths withIndexDo: [:aWidth :idx| self printLineSized: aWidth.
Expand Down
39 changes: 39 additions & 0 deletions src/PharoLauncher-CLI/PhLCliCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ PhLCliCommand >> cliFormatter: aFormatter [
cliFormatter := aFormatter
]

{ #category : #default }
PhLCliCommand >> defaultTemplate [

^ self pharoLauncherModel defaultTemplate = #dev
ifTrue: [ self latestDevTemplate ]
ifFalse: [ self latestStableTemplate ]
]

{ #category : #default }
PhLCliCommand >> defaultTemplateCategory [
^ self templateRepository
Expand Down Expand Up @@ -261,6 +269,30 @@ PhLCliCommand >> initialize [
self cliFormatter: (ConsoleListFormatter on: self).
]

{ #category : #default }
PhLCliCommand >> isDefaultTemplateCategory: aCategory ifTrue: trueBlock ifFalse: falseBlock [

[ aCategory == self defaultTemplateCategory
ifTrue: trueBlock
ifFalse: falseBlock ]
on: NotFound "default template category not found"
do: falseBlock
]

{ #category : #default }
PhLCliCommand >> latestDevTemplate [

"from default 'Official distributions' obtain latest development template"
^ self defaultTemplateCategory latestDevelopmentTemplate
]

{ #category : #default }
PhLCliCommand >> latestStableTemplate [

"from default 'Official distributions' obtain latest Pharo version stable template"
^ self defaultTemplateCategory latestStableTemplate
]

{ #category : #printing }
PhLCliCommand >> list: domainObjects [

Expand All @@ -269,6 +301,13 @@ PhLCliCommand >> list: domainObjects [
printList.
]

{ #category : #printing }
PhLCliCommand >> list: domainObjects default: defaultValue [
self cliFormatter
domainObjects: domainObjects defaultValue: defaultValue;
printList.
]

{ #category : #private }
PhLCliCommand >> listPrintAttributeBlocks [

Expand Down
22 changes: 0 additions & 22 deletions src/PharoLauncher-CLI/PhLImageCreateCliCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ PhLImageCreateCliCommand >> createImage: newImageName from: template [
^ anImage
]

{ #category : #default }
PhLImageCreateCliCommand >> defaultTemplate [

^ self pharoLauncherModel defaultTemplate = #dev
ifTrue: [ self latestDevTemplate ]
ifFalse: [ self latestStableTemplate ]
]

{ #category : #querying }
PhLImageCreateCliCommand >> findTemplate [
(self hasFlag: #dev) ifTrue: [ ^ self latestDevTemplate ].
Expand Down Expand Up @@ -229,20 +221,6 @@ PhLImageCreateCliCommand >> implicitPharoVersion [
^ self imageFinderClass findLatestPharoDevelopmentVersion
]

{ #category : #default }
PhLImageCreateCliCommand >> latestDevTemplate [

"from default 'Official distributions' obtain latest development template"
^ self defaultTemplateCategory latestDevelopmentTemplate
]

{ #category : #default }
PhLImageCreateCliCommand >> latestStableTemplate [

"from default 'Official distributions' obtain latest Pharo version stable template"
^ self defaultTemplateCategory latestStableTemplate
]

{ #category : #logging }
PhLImageCreateCliCommand >> logCannotFindTemplate: templateName [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ PhLTemplateCategoriesCliCommand class >> launcherCmdDescription [
{ #category : #'command execution' }
PhLTemplateCategoriesCliCommand >> basicExecute [

self list: self templateRepository roots
[ self list: self templateRepository roots default: self defaultTemplateCategory ]
on: NotFound
do: [ self list: self templateRepository roots ]
]

{ #category : #private }
Expand Down
7 changes: 5 additions & 2 deletions src/PharoLauncher-CLI/PhLTemplateListCliCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ PhLTemplateListCliCommand >> basicExecute [
categoryNamed: self templateCategory ]
on: NotFound
do: [ ^ self raiseCategoryNotFound: self templateCategory ].

self list: templateCategory templatesAndGroups asOrderedCollection

self
isDefaultTemplateCategory: templateCategory
ifTrue: [ self list: templateCategory templatesAndGroups asOrderedCollection default: self defaultTemplate ]
ifFalse: [ self list: templateCategory templatesAndGroups asOrderedCollection ]
]

{ #category : #message }
Expand Down

0 comments on commit 9111e06

Please sign in to comment.