forked from bonzini/smalltalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getopt.st
74 lines (69 loc) · 3.17 KB
/
getopt.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"======================================================================
|
| Smalltalk command-line parser tests
|
|
======================================================================"
"======================================================================
|
| Copyright 2006, 2007 Free Software Foundation, Inc.
| Written by Paolo Bonzini.
|
| This file is part of the GNU Smalltalk class library.
|
| The GNU Smalltalk class library is free software; you can redistribute it
| and/or modify it under the terms of the GNU Lesser General Public License
| as published by the Free Software Foundation; either version 2.1, or (at
| your option) any later version.
|
| The GNU Smalltalk class library is distributed in the hope that it will be
| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
| General Public License for more details.
|
| You should have received a copy of the GNU Lesser General Public License
| along with the GNU Smalltalk class library; see the file COPYING.LIB.
| If not, write to the Free Software Foundation, 59 Temple Place - Suite
| 330, Boston, MA 02110-1301, USA.
|
======================================================================"
Getopt extend [
Getopt class [
test: args with: pattern [
args do: [ :each |
self
parse: each subStrings
with: pattern
do: [ :x :y | (x->y) printNl ]
ifError: [ (each->'error') displayNl ].
Transcript nl ]
]
]
testParsing: p [
self parsePattern: p.
prefixes asSortedCollection printNl.
(options keys asSortedCollection: [ :a :b | a asString < b asString ])
do: [ :k | (options associationAt: k) printNl ]
]
]
Eval [ Getopt new testParsing: '-B' ]
Eval [ Getopt new testParsing: '--long' ]
Eval [ Getopt new testParsing: '--longish --longer' ]
Eval [ Getopt new testParsing: '--long --longer' ]
Eval [ Getopt new testParsing: '-B:' ]
Eval [ Getopt new testParsing: '-B::' ]
Eval [ Getopt new testParsing: '-a|-b' ]
Eval [ Getopt new testParsing: '-a|--long' ]
Eval [ Getopt new testParsing: '-a|--very-long|--long' ]
Eval [ Getopt test: #('-a' '-b' '-ab' '-a -b') with: '-a -b' ]
Eval [ Getopt test: #('-a' '-b' '-ab' '-a -b') with: '-a: -b' ]
Eval [ Getopt test: #('-a' '-b' '-ab' '-a -b') with: '-a:: -b' ]
Eval [ Getopt test: #('--longish' '--longer' '--longi' '--longe' '--lo' '-longer') with: '--longish --longer' ]
Eval [ Getopt test: #('--lo' '--long' '--longe' '--longer') with: '--long --longer' ]
Eval [ Getopt test: #('--noarg' '--mandatory' '--mandatory foo' '--mandatory=' '--mandatory=foo' '--optional' '--optional foo') with: '--noarg --mandatory: --optional::' ]
Eval [ Getopt test: #('-a' '-b') with: '-a|-b' ]
Eval [ Getopt test: #('--long' '-b') with: '-b|--long' ]
Eval [ Getopt test: #('--long=x' '-bx') with: '-b|--long:' ]
Eval [ Getopt test: #('-b' '--long' '--very-long') with: '-b|--very-long|--long' ]
Eval [ Getopt test: #('--long=x' '--very-long x' '-bx') with: '-b|--very-long|--long:' ]
Eval [ Getopt test: #('-b -- -b' '-- -b' '-- -b -b') with: '-b' ]