Permalink
Browse files

New cool construction syntax.

  • Loading branch information...
1 parent 364171c commit a0d9f25d3ed833f3feebb198675d44f7c072660a @fredreichbier committed Mar 7, 2010
Showing with 27 additions and 22 deletions.
  1. +21 −19 optparse/Option.ooc
  2. +6 −3 test.ooc
View
@@ -5,16 +5,19 @@ import optparse/Parser
Option: abstract class {
key: String
+ init: func (=key) {}
+
storeValue: func <T> (parser: Parser, value: T) {
parser values put(key, value)
}
-
+
storeDefault: abstract func (parser: Parser)
activate: abstract func (parser: Parser, reader: CommandLineReader) -> Bool
}
SimpleOption: abstract class extends Option {
- longName, shortName: String
+ longName := ""
+ shortName := ""
activate: func (parser: Parser, reader: CommandLineReader) -> Bool {
token := reader peek()
@@ -29,19 +32,17 @@ SimpleOption: abstract class extends Option {
return false
}
+ longName: func (=longName) {}
+ shortName: func (=shortName) {}
+
activate2: abstract func (parser: Parser, reader: CommandLineReader)
}
ToggleOption: class extends SimpleOption {
- store, defaultValue: Bool
+ store := true
+ defaultValue := false
- init: func ~verbose (=key, =longName, =shortName, =store, =defaultValue) {
-
- }
-
- init: func ~storeTrue (=key, =longName, =shortName, =defaultValue) {
- store = true
- }
+ init: func ~doggl (=key) {}
activate2: func (parser: Parser, reader: CommandLineReader) {
storeValue(parser, store)
@@ -50,29 +51,30 @@ ToggleOption: class extends SimpleOption {
storeDefault: func (parser: Parser) {
storeValue(parser, defaultValue)
}
+
+ store: func (=store) {}
+ defaultValue: func (=defaultValue) {}
}
StringOption: class extends SimpleOption {
- defaultValue: String
+ defaultValue := ""
+
+ init: func ~s (=key) {}
- init: func (=key, =longName, =shortName, =defaultValue) {
-
- }
-
activate2: func (parser: Parser, reader: CommandLineReader) {
storeValue(parser, reader get())
}
storeDefault: func (parser: Parser) {
storeValue(parser, defaultValue)
}
+
+ defaultValue: func (=defaultValue) {}
}
ListOption: class extends SimpleOption {
- init: func (=key, =longName, =shortName) {
-
- }
-
+ init: func ~ichLiebeWurstsalat (=key) {}
+
activate2: func (parser: Parser, reader: CommandLineReader) {
parser values get(key, ArrayList<String>) add(reader get())
}
View
@@ -11,9 +11,12 @@ test: func (parser: Parser, args: ArrayList<String>) {
main: func (args: Array<String>) {
parser := Parser new()
- parser addOption(ToggleOption new("quiet", "quiet", "q", false))
- parser addOption(StringOption new("name", "name", "n", "Bla-Bli-Blubb"))
- parser addOption(ListOption new("libs", "lib", "l"))
+
+ quiet := ToggleOption new("quiet") .longName("quiet") .shortName("q")
+ name := StringOption new("name") .longName("name") .shortName("n")
+ libs := ListOption new("libs") .longName("lib") .shortName("l")
+
+ parser addOption(quiet) .addOption(name) .addOption(libs)
test(parser, args toArrayList())
}

0 comments on commit a0d9f25

Please sign in to comment.