author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 14 Jun 2016 07:04:34 +0100 | |
branch | jv |
changeset 19988 | 148721e96482 |
parent 18011 | deb0c3355881 |
child 20076 | ff2f4d06a2fa |
permissions | -rw-r--r-- |
13402 | 1 |
" |
13938 | 2 |
COPYRIGHT (c) 2006 by eXept Software AG |
13402 | 3 |
All Rights Reserved |
4 |
||
13938 | 5 |
This software is furnished under a license and may be used |
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
13402 | 11 |
" |
12 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
14 |
"{ NameSpace: Smalltalk }" |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
15 |
|
13402 | 16 |
Object subclass:#CmdLineOption |
17 |
instanceVariableNames:'action description short long' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'System-Support-Command line' |
|
21 |
! |
|
22 |
||
23 |
!CmdLineOption class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
13938 | 27 |
COPYRIGHT (c) 2006 by eXept Software AG |
13402 | 28 |
All Rights Reserved |
29 |
||
13938 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
13482 | 38 |
|
13938 | 39 |
optionsFor: anObject |
13482 | 40 |
|
13938 | 41 |
"Returns a collection of command line options for |
42 |
given object." |
|
43 |
||
44 |
^anObject class allSelectors |
|
45 |
select:[:sel|sel startsWith: 'cmdlineOption'] |
|
46 |
thenCollect:[:sel|anObject perform: sel]. |
|
13402 | 47 |
! ! |
48 |
||
49 |
!CmdLineOption methodsFor:'accessing'! |
|
50 |
||
51 |
action |
|
52 |
^ action |
|
53 |
||
54 |
"Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
55 |
! |
|
56 |
||
57 |
action:aBlockOrMessageSend |
|
58 |
||
59 |
aBlockOrMessageSend numArgs > 1 ifTrue: |
|
60 |
[CmdLineOptionError raiseErrorString: 'Action must be zero-or-one arg block/message send']. |
|
61 |
action := aBlockOrMessageSend. |
|
62 |
||
63 |
"Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
64 |
"Modified: / 16-06-2009 / 15:46:54 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
65 |
! |
|
66 |
||
67 |
description |
|
68 |
^ description |
|
69 |
||
70 |
"Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
71 |
! |
|
72 |
||
73 |
description:aString |
|
74 |
description := aString. |
|
75 |
||
76 |
"Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
77 |
! |
|
78 |
||
79 |
long |
|
80 |
^ long |
|
81 |
! |
|
82 |
||
83 |
long:aString |
|
84 |
long := aString. |
|
85 |
! |
|
86 |
||
87 |
short |
|
88 |
^ short |
|
89 |
! |
|
90 |
||
91 |
short:aCharacterOrString |
|
92 |
||
93 |
(aCharacterOrString isCharacter |
|
94 |
and:[aCharacterOrString isAlphaNumeric]) |
|
95 |
ifTrue:[short := aCharacterOrString] |
|
96 |
ifFalse:[self error: 'short option name should be alphanumeric character'] |
|
97 |
||
98 |
"Modified: / 29-05-2009 / 16:05:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
99 |
! |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
100 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
101 |
spec: spec |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
102 |
"Build an option from option specification" |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
103 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
104 |
long := short := nil. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
105 |
(spec isCollection and:[ spec isString not ]) ifTrue:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
106 |
spec do:[:each | self spec0: each ] |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
107 |
] ifFalse:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
108 |
self spec0: spec. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
109 |
]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
110 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
111 |
"Created: / 14-06-2016 / 06:46:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13402 | 112 |
! ! |
113 |
||
114 |
!CmdLineOption methodsFor:'printing & storing'! |
|
115 |
||
116 |
printOn: stream |
|
117 |
||
118 |
super printOn: stream. |
|
119 |
stream nextPut:$(. |
|
120 |
short ifNotNil:[stream nextPut: $-; nextPut: short]. |
|
121 |
(short notNil and: [long notNil]) ifTrue:[stream nextPut:$|]. |
|
122 |
long ifNotNil:[stream nextPut: $-; nextPut: $-; nextPutAll: long]. |
|
123 |
stream nextPut:$) |
|
124 |
||
125 |
"Created: / 08-06-2009 / 14:48:59 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
126 |
! ! |
|
127 |
||
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
128 |
!CmdLineOption methodsFor:'private'! |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
129 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
130 |
spec0:aStringOrCharacter |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
131 |
aStringOrCharacter isCharacter ifTrue:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
132 |
short notNil ifTrue:[ self error: 'Short option already specified: ', short asString ]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
133 |
short := aStringOrCharacter. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
134 |
^ self. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
135 |
]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
136 |
aStringOrCharacter isString ifTrue:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
137 |
| l | |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
138 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
139 |
l := aStringOrCharacter. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
140 |
l first == $- ifTrue:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
141 |
l second == $- ifTrue:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
142 |
l := l copyFrom: 3. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
143 |
] ifFalse:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
144 |
(l size == 2 and:[ l second isAlphaNumeric ]) ifTrue:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
145 |
short notNil ifTrue:[ self error: 'Short option already specified: ', short asString ]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
146 |
short := l second. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
147 |
^ self. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
148 |
]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
149 |
]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
150 |
]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
151 |
long notNil ifTrue: [ self error: 'Long (GNU-style) option already specified: ', short asString ]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
152 |
(l allSatisfy: [:c | c isAlphaNumeric ]) ifTrue:[ |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
153 |
long := l. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
154 |
^ self. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
155 |
]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
156 |
]. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
157 |
self error: 'Invalid option specification: ' , aStringOrCharacter asString. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
158 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
159 |
"Created: / 14-06-2016 / 06:46:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
160 |
! ! |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
161 |
|
13402 | 162 |
!CmdLineOption methodsFor:'processing'! |
163 |
||
164 |
process |
|
165 |
||
166 |
action value |
|
167 |
||
168 |
"Created: / 08-06-2009 / 14:35:01 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
169 |
! |
|
170 |
||
171 |
process: value |
|
172 |
||
173 |
action value: value |
|
174 |
||
175 |
"Created: / 08-06-2009 / 14:35:08 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
176 |
! ! |
|
177 |
||
178 |
!CmdLineOption methodsFor:'queries'! |
|
179 |
||
180 |
hasParam |
|
181 |
||
182 |
^action numArgs = 1 |
|
183 |
||
184 |
"Created: / 08-06-2009 / 13:45:41 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
185 |
! ! |
|
186 |
||
187 |
!CmdLineOption class methodsFor:'documentation'! |
|
188 |
||
13938 | 189 |
version |
190 |
^'$Header: /cvs/stx/stx/libbasic/CmdLineOption.st,v 1.3 2012-01-13 10:58:29 vrany Exp $' |
|
13402 | 191 |
! |
192 |
||
193 |
version_SVN |
|
13938 | 194 |
^ '§Id: CmdLineOption.st 10737 2011-11-06 21:23:48Z vranyj1 §' |
13402 | 195 |
! ! |
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18011
diff
changeset
|
196 |