Permalink
Browse files

Make it work with latest rock.

  • Loading branch information...
1 parent 7e94e9c commit 164faf80561f82ef68ac888903a04afee752d47b @fredreichbier committed Dec 21, 2011
Showing with 22 additions and 21 deletions.
  1. +10 −9 optparse/Option.ooc
  2. +8 −8 optparse/Parser.ooc
  3. +4 −4 test.ooc
View
@@ -1,5 +1,4 @@
import structs/[HashBag, HashMap, ArrayList]
-import text/Buffer
import optparse/Parser
@@ -26,12 +25,14 @@ SimpleOption: abstract class extends Option {
longName := ""
shortName := ""
+ init: func ~noarg {} // heaven knows
+
activate: func (parser: Parser, reader: CommandLineReader) -> Bool {
token := reader peek()
longNameTemplate := "--" + longName
shortNameTemplate := "-" + shortName
- if((!longName isEmpty() && token equals(longNameTemplate)) \
- || (!shortName isEmpty() && token equals(shortNameTemplate))) {
+ if((!longName empty?() && token == longNameTemplate) \
+ || (!shortName empty?() && token == shortNameTemplate)) {
reader skip()
activate2(parser, reader)
return true
@@ -43,26 +44,26 @@ SimpleOption: abstract class extends Option {
buf := Buffer new()
buf append(" ")
// has short name.
- if(!shortName isEmpty()) {
+ if(!shortName empty?()) {
buf append("-%s" format(shortName))
- if(!longName isEmpty()) {
+ if(!longName empty?()) {
buf append(", ")
}
}
// has long name.
- if(!longName isEmpty()) {
+ if(!longName empty?()) {
buf append("--%s" format(longName))
}
// metavar!
- if(!metaVar isEmpty()) {
+ if(!metaVar empty?()) {
buf append(' ') .append(metaVar)
} else {
buf append("\t")
}
// tab!
buf append("\t\t")
// description!
- if(!help isEmpty()) {
+ if(!help empty?()) {
buf append(help)
}
buf append('\n')
@@ -128,7 +129,7 @@ MapOption: class extends SimpleOption {
token := reader get()
key := ""
value := ""
- if(token contains('=')) {
+ if(token contains?('=')) {
key = token substring(0, token indexOf('='))
value = token substring(token indexOf('=') + 1)
} else {
View
@@ -1,17 +1,17 @@
import structs/[ArrayList, HashBag]
-import text/[Buffer, StringTokenizer]
+import text/[StringTokenizer]
import optparse/Option
ParserError: class extends Exception {
parser: Parser
- init: func ~withMsg (=parser, .msg) {
- super(msg)
+ init: func ~withMsg (=parser, .message) {
+ super(message)
}
print: func {
- fprintf(stderr, "%s", getMessage())
+ "%s" printfln(message)
parser displayHelp()
}
}
@@ -20,7 +20,7 @@ ParserError: class extends Exception {
transformArgs: func (args: ArrayList<String>) -> ArrayList<String> {
result := ArrayList<String> new()
for(arg in args) {
- if(arg contains('=')) {
+ if(arg contains?('=')) {
// split!
result addAll(arg split('=', 1))
} else {
@@ -40,11 +40,11 @@ CommandLineReader: class {
}
isValid: func -> Bool {
- index < args size()
+ index < args size
}
peek: func -> String {
- if(index >= args size()) {
+ if(index >= args size) {
parser error("I smell incompleteness.")
} else {
return args[index]
@@ -57,7 +57,7 @@ CommandLineReader: class {
get: func -> String {
index += 1
- if(index > args size()) {
+ if(index > args size) {
parser error("I smell incompleteness.")
} else {
return args[index - 1]
View
@@ -7,8 +7,8 @@ test: func (parser: Parser, args: ArrayList<String>) {
"Quiet: %d " format(parser values get("quiet", Bool)) println()
"Libs: %s" format(parser values get("libs", ArrayList<String>) join(", ")) println()
"Config:" println()
- cfg := parser values get("cfg", HashMap<String>)
- for(key in cfg keys) {
+ cfg := parser values get("cfg", HashMap<String, String>)
+ for(key in cfg getKeys()) {
" '%s' => '%s'" format(key, cfg[key]) println()
}
"Positional: %s" format(parser positional join(' ')) println()
@@ -24,9 +24,9 @@ main: func (args: ArrayList<String>) {
parser addOption(quiet) .addOption(name) .addOption(libs) .addOption(cfg)
- if(args size() < 2) {
+ if(args size < 2) {
parser displayHelp()
} else {
- test(parser, args toArrayList())
+ test(parser, args)
}
}

0 comments on commit 164faf8

Please sign in to comment.