equal
deleted
inserted
replaced
8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 "{ Package: 'stx:libbasic' }" |
12 "{ Package: 'stx:libbasic' }" |
|
13 |
|
14 "{ NameSpace: Smalltalk }" |
13 |
15 |
14 Object subclass:#CmdLineOption |
16 Object subclass:#CmdLineOption |
15 instanceVariableNames:'action description short long' |
17 instanceVariableNames:'action description short long' |
16 classVariableNames:'' |
18 classVariableNames:'' |
17 poolDictionaries:'' |
19 poolDictionaries:'' |
92 and:[aCharacterOrString isAlphaNumeric]) |
94 and:[aCharacterOrString isAlphaNumeric]) |
93 ifTrue:[short := aCharacterOrString] |
95 ifTrue:[short := aCharacterOrString] |
94 ifFalse:[self error: 'short option name should be alphanumeric character'] |
96 ifFalse:[self error: 'short option name should be alphanumeric character'] |
95 |
97 |
96 "Modified: / 29-05-2009 / 16:05:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
98 "Modified: / 29-05-2009 / 16:05:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
99 ! |
|
100 |
|
101 spec: spec |
|
102 "Build an option from option specification" |
|
103 |
|
104 long := short := nil. |
|
105 (spec isCollection and:[ spec isString not ]) ifTrue:[ |
|
106 spec do:[:each | self spec0: each ] |
|
107 ] ifFalse:[ |
|
108 self spec0: spec. |
|
109 ]. |
|
110 |
|
111 "Created: / 14-06-2016 / 06:46:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
97 ! ! |
112 ! ! |
98 |
113 |
99 !CmdLineOption methodsFor:'printing & storing'! |
114 !CmdLineOption methodsFor:'printing & storing'! |
100 |
115 |
101 printOn: stream |
116 printOn: stream |
106 (short notNil and: [long notNil]) ifTrue:[stream nextPut:$|]. |
121 (short notNil and: [long notNil]) ifTrue:[stream nextPut:$|]. |
107 long ifNotNil:[stream nextPut: $-; nextPut: $-; nextPutAll: long]. |
122 long ifNotNil:[stream nextPut: $-; nextPut: $-; nextPutAll: long]. |
108 stream nextPut:$) |
123 stream nextPut:$) |
109 |
124 |
110 "Created: / 08-06-2009 / 14:48:59 / Jan Vrany <vranyj1@fel.cvut.cz>" |
125 "Created: / 08-06-2009 / 14:48:59 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
126 ! ! |
|
127 |
|
128 !CmdLineOption methodsFor:'private'! |
|
129 |
|
130 spec0:aStringOrCharacter |
|
131 aStringOrCharacter isCharacter ifTrue:[ |
|
132 short notNil ifTrue:[ self error: 'Short option already specified: ', short asString ]. |
|
133 short := aStringOrCharacter. |
|
134 ^ self. |
|
135 ]. |
|
136 aStringOrCharacter isString ifTrue:[ |
|
137 | l | |
|
138 |
|
139 l := aStringOrCharacter. |
|
140 l first == $- ifTrue:[ |
|
141 l second == $- ifTrue:[ |
|
142 l := l copyFrom: 3. |
|
143 ] ifFalse:[ |
|
144 (l size == 2 and:[ l second isAlphaNumeric ]) ifTrue:[ |
|
145 short notNil ifTrue:[ self error: 'Short option already specified: ', short asString ]. |
|
146 short := l second. |
|
147 ^ self. |
|
148 ]. |
|
149 ]. |
|
150 ]. |
|
151 long notNil ifTrue: [ self error: 'Long (GNU-style) option already specified: ', short asString ]. |
|
152 (l allSatisfy: [:c | c isAlphaNumeric ]) ifTrue:[ |
|
153 long := l. |
|
154 ^ self. |
|
155 ]. |
|
156 ]. |
|
157 self error: 'Invalid option specification: ' , aStringOrCharacter asString. |
|
158 |
|
159 "Created: / 14-06-2016 / 06:46:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
111 ! ! |
160 ! ! |
112 |
161 |
113 !CmdLineOption methodsFor:'processing'! |
162 !CmdLineOption methodsFor:'processing'! |
114 |
163 |
115 process |
164 process |
142 ! |
191 ! |
143 |
192 |
144 version_SVN |
193 version_SVN |
145 ^ '§Id: CmdLineOption.st 10737 2011-11-06 21:23:48Z vranyj1 §' |
194 ^ '§Id: CmdLineOption.st 10737 2011-11-06 21:23:48Z vranyj1 §' |
146 ! ! |
195 ! ! |
|
196 |