1 lobby ensureNamespace: #Shell.
3 Shell define: #FileArray &parents: {ExtensibleArray}.
4 Shell define: #FormatSpecification &parents: {Cloneable} &slots: {#spec}.
6 Shell FormatSpecification traits define: #codes -> (Dictionary new*,
7 $p -> [|:l| l as: String],
12 $f -> [|:l| [|:s| l writeNameVersionTypeOn: s] writingAs: String]).
14 ffs@(Shell FormatSpecification traits) newFrom: s@(String traits)
16 writer: ExtensibleArray new writer.
18 writer nextPut: (input upTo: $%).
20 writer nextPut: (Shell FormatSpecification codes at: each ifAbsent: [error: 'bad code: ' ; each printString]).
21 writer nextPut: (input upTo: $%)].
22 ffs new `>> [spec: (writer contents reject: [| :each | (each is: String) /\ [each isEmpty]]). ]
25 ffs@(Shell FormatSpecification traits) format: f@(File Locator traits)
31 ifTrue: [s nextPutAll: each]
32 ifFalse: [s nextPutAll: (each applyWith: f)]]] writingAs: String
35 d@(File Locator traits) maskedEntries: mask@(String traits) do: block
37 d maskedEntries: (Shell MaskPattern newOn: mask) do: block
40 l@(File Locator traits) maskedEntries: mask@(Regex Regex traits) do: block
42 matcher: (Regex Matcher newOn: mask).
43 (Directory new `>> [locator: l. ]) reader reset
44 do: [|:each| (matcher match: each) = Regex Matcher Fail ifFalse: [block applyWith: (l clone `>> [readFilenameFrom: each. ])]].
47 l@(File Locator traits) maskedEntries: mask@(Shell MaskPattern traits) do: block
49 (Directory new `>> [locator: l. ]) reader reset
50 do: [|:each| (mask matches: each) ifTrue: [block applyWith: (l clone `>> [readFilenameFrom: each. ])]].
53 d@(File Locator traits) collectMasked: mask
55 [|:result| d maskedEntries: mask do: #nextPut: `er <- result. result] writingAs: Shell FileArray
58 d@(File Locator traits) /* mask
59 [d collectMasked: mask].
61 d@(Directory traits) /* mask
62 [d locator collectMasked: mask].
64 a@(Shell FileArray traits) format: formatString@(String traits)
66 fmtSpec: (Shell FormatSpecification newFrom: formatString).
67 a collect: [|:each| fmtSpec format: each]
70 a@(Shell FileArray traits) format*
72 fmtSpecs: (args collect: [|:each| Shell FormatSpecification newFrom: each]).
73 a collect: [|:each| fmtSpecs collect: [|:spec| spec format: each]]