diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/README.md b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/README.md new file mode 100644 index 00000000..e69de29b diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/commandLine.redirectTarget..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/commandLine.redirectTarget..st new file mode 100644 index 00000000..82355e0d --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/commandLine.redirectTarget..st @@ -0,0 +1,6 @@ +instance creation +commandLine: commandLine redirectTarget: redirectTarget + ^ self new + commandLine: commandLine; + redirectTarget: redirectTarget; + yourself \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/fromStream.forEachCommand..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/fromStream.forEachCommand..st new file mode 100644 index 00000000..88a80b57 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/fromStream.forEachCommand..st @@ -0,0 +1,5 @@ +parsing +fromStream: aStream forEachCommand: aBlock + "multi-line input" + + self fromStream: aStream selectLine: [:cmdLine | true] forEachCommand: aBlock \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/fromStream.selectLine.forEachCommand..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/fromStream.selectLine.forEachCommand..st new file mode 100644 index 00000000..6eb376c6 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/fromStream.selectLine.forEachCommand..st @@ -0,0 +1,29 @@ +parsing +fromStream: aStream selectLine: selectLineBlock forEachCommand: aBlock + "multi-line input" + + | cmdLines line escaped lastLine | + cmdLines := OrderedCollection new. + escaped := false. + lastLine := ''. + [ aStream atEnd ] + whileFalse: [ + line := aStream nextLine. + (line isNil or: [ line isEmpty ]) + ifFalse: [ + (line isEmpty not and: [ line last == $\ ]) + ifTrue: [ + escaped := true. + lastLine := lastLine , (line copyFrom: 1 to: line size - 1) ] + ifFalse: [ + escaped + ifTrue: [ + cmdLines add: lastLine , line. + escaped := false ] + ifFalse: [ cmdLines add: line ] ] ] ]. + escaped + ifTrue: [ cmdLines add: lastLine ]. + cmdLines + do: [ :cmdLine | + (selectLineBlock value: cmdLine) + ifTrue: [ self line: cmdLine forEachCommand: aBlock ] ] \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/isolate..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/isolate..st new file mode 100644 index 00000000..2957a1cf --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/isolate..st @@ -0,0 +1,30 @@ +private +isolate: aString + | isolated command final escaped skipComment | + isolated := OrderedCollection new. + command := WriteStream on: String new. + skipComment := escaped := false. + aString + do: [ :char | + skipComment + ifFalse: [ + escaped + ifTrue: [ + command nextPut: char. + char = $` + ifTrue: [ escaped := false ] ] + ifFalse: [ + char == $; + ifTrue: [ + isolated add: command contents. + command := WriteStream on: String new ] + ifFalse: [ + char == $# + ifTrue: [ skipComment := true ] + ifFalse: [ command nextPut: char ] ]. + char = $` + ifTrue: [ escaped := true ] ] ] ]. + final := command contents. + final isEmpty + ifFalse: [ isolated add: final ]. + ^ isolated \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/line.forEachCommand..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/line.forEachCommand..st new file mode 100644 index 00000000..5e38b743 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/line.forEachCommand..st @@ -0,0 +1,13 @@ +parsing +line: cmdLineString forEachCommand: aBlock + "single command line" + + (self isolate: cmdLineString) + do: [ :isolated | + | redirected commandLine redirectTarget command | + redirected := self scan: isolated delim: $>. + commandLine := redirected at: 1. + redirectTarget := redirected size > 1 + ifTrue: [ (redirected at: 2) trimBoth ]. + command := self commandLine: commandLine redirectTarget: redirectTarget. + aBlock value: command ] \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/scan.delim..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/scan.delim..st new file mode 100644 index 00000000..e255a6b2 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/class/scan.delim..st @@ -0,0 +1,34 @@ +private +scan: aString delim: delim + | scanned command stream final escaped | + scanned := OrderedCollection new. + command := WriteStream on: String new. + stream := ReadStream on: aString. + escaped := false. + [ stream atEnd ] + whileFalse: [ + | char | + char := stream next. + escaped + ifTrue: [ + char = $` + ifTrue: [ escaped := false ]. + command nextPut: char ] + ifFalse: [ + char == Character space + ifTrue: [ + stream peek == delim + ifTrue: [ + scanned add: command contents. + command := WriteStream on: String new. + stream next. + command nextPut: stream next ] + ifFalse: [ command nextPut: char ] ] + ifFalse: [ + char = $` + ifTrue: [ escaped := true ]. + command nextPut: char ] ] ]. + final := command contents. + final isEmpty + ifFalse: [ scanned add: final ]. + ^ scanned \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/argPtrs.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/argPtrs.st new file mode 100644 index 00000000..652f9fd3 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/argPtrs.st @@ -0,0 +1,4 @@ +private +argPtrs + self tokens. "ensure argPtrs defined" + ^ argPtrs \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/command.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/command.st new file mode 100644 index 00000000..6ad5362f --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/command.st @@ -0,0 +1,3 @@ +accessing +command + ^ self rawTokens at: 1 \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandArgPtr.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandArgPtr.st new file mode 100644 index 00000000..d7b1288e --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandArgPtr.st @@ -0,0 +1,3 @@ +private +commandArgPtr + ^ self argPtrs at: 1 \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandLine..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandLine..st new file mode 100644 index 00000000..94e74558 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandLine..st @@ -0,0 +1,3 @@ +private +commandLine: aString + commandLine := aString trimBoth \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandLine.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandLine.st new file mode 100644 index 00000000..30377764 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/commandLine.st @@ -0,0 +1,3 @@ +accessing +commandLine + ^ commandLine \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandLongOpts.short.do.argsDo..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandLongOpts.short.do.argsDo..st new file mode 100644 index 00000000..0819252b --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandLongOpts.short.do.argsDo..st @@ -0,0 +1,11 @@ +private +getCommandLongOpts: optionSpec short: shortOptionAliases do: optionBlock argsDo: argBlock + | optionStream optionString | + optionString := commandLine copyFrom: self commandArgPtr to: commandLine size. + optionStream := ReadStream on: optionString. + TDCommandGetOpts + getOptsLongFor: optionStream + longOptionSpec: optionSpec + shortOptionAliases: shortOptionAliases + do: optionBlock + nonOptionsDo: argBlock \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandOpts.do.argsDo..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandOpts.do.argsDo..st new file mode 100644 index 00000000..43e0ab0f --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandOpts.do.argsDo..st @@ -0,0 +1,10 @@ +private +getCommandOpts: optionSpec do: optionBlock argsDo: argBlock + | optionStream optionString | + optionString := commandLine copyFrom: self commandArgPtr to: commandLine size. + optionStream := ReadStream on: optionString. + TDCommandGetOpts + getOptsFor: optionStream + spec: optionSpec + do: optionBlock + nonOptionsDo: argBlock \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandOpts.optionsAndArguments..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandOpts.optionsAndArguments..st new file mode 100644 index 00000000..7e382995 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getCommandOpts.optionsAndArguments..st @@ -0,0 +1,10 @@ +private +getCommandOpts: optionSpec optionsAndArguments: optsAndArgsBlock + | options args | + options := Dictionary new. + args := OrderedCollection new. + self + getCommandOpts: optionSpec + do: [ :option :optionArg | options at: option asString put: optionArg ] + argsDo: [ :arg | args add: arg ]. + optsAndArgsBlock value: options value: args \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOpts.optionsAndArguments..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOpts.optionsAndArguments..st new file mode 100644 index 00000000..6800a8bf --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOpts.optionsAndArguments..st @@ -0,0 +1,17 @@ +parsing +getOpts: optionSpec optionsAndArguments: optsAndArgsBlock + | options args | + options := Dictionary new. + args := OrderedCollection new. + self hasSubCommand + ifTrue: [ + self + getSubCommandOpts: optionSpec + do: [ :option :optionArg | options at: option asString put: optionArg ] + argsDo: [ :arg | args add: arg ] ] + ifFalse: [ + self + getCommandOpts: optionSpec + do: [ :option :optionArg | options at: option asString put: optionArg ] + argsDo: [ :arg | args add: arg ] ]. + ^ optsAndArgsBlock value: options value: args \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOpts.subOpts.optionsAndArguments..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOpts.subOpts.optionsAndArguments..st new file mode 100644 index 00000000..fe18a7b1 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOpts.subOpts.optionsAndArguments..st @@ -0,0 +1,27 @@ +parsing +getOpts: optionSpecs subOpts: subOptionSpecs optionsAndArguments: optsAndArgsBlock + | options arguments subCommandArgPtrIndex subCommandLine subCommand subOptions subArguments | + self + getOptsMixedLongShort: optionSpecs + optionsAndArguments: [ :optionDictionary :argsIn | + options := optionDictionary. + arguments := argsIn ]. + subCommandArgPtrIndex := self rawTokens size - arguments size. + subCommandLine := self commandLine + copyFrom: (self argPtrs at: subCommandArgPtrIndex) + to: self commandLine size. + TDCommandLine + line: subCommandLine + forEachCommand: [ :aCommand | + subCommand := aCommand. + subCommand + getOptsMixedLongShort: subOptionSpecs + optionsAndArguments: [ :optionDictionary :argsIn | + subOptions := optionDictionary. + subArguments := argsIn ] ]. + ^ optsAndArgsBlock + value: options + value: arguments + value: subCommand command + value: subOptions + value: subArguments \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsLong.optionsAndArguments..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsLong.optionsAndArguments..st new file mode 100644 index 00000000..c672a737 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsLong.optionsAndArguments..st @@ -0,0 +1,6 @@ +parsing +getOptsLong: longOptionSpec optionsAndArguments: optsAndArgsBlock + ^ self + getOptsLong: longOptionSpec + short: Dictionary new + optionsAndArguments: optsAndArgsBlock \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsLong.short.optionsAndArguments..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsLong.short.optionsAndArguments..st new file mode 100644 index 00000000..3a59aa5e --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsLong.short.optionsAndArguments..st @@ -0,0 +1,19 @@ +parsing +getOptsLong: longOptionSpec short: shortOptionAliases optionsAndArguments: optsAndArgsBlock + | options args | + options := Dictionary new. + args := OrderedCollection new. + self hasSubCommand + ifTrue: [ + self + getSubCommandLongOpts: longOptionSpec + short: shortOptionAliases + do: [ :option :optionArg | options at: option asString put: optionArg ] + argsDo: [ :arg | args add: arg ] ] + ifFalse: [ + self + getCommandLongOpts: longOptionSpec + short: shortOptionAliases + do: [ :option :optionArg | options at: option asString put: optionArg ] + argsDo: [ :arg | args add: arg ] ]. + ^ optsAndArgsBlock value: options value: args \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsMixedLongShort.optionsAndArguments..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsMixedLongShort.optionsAndArguments..st new file mode 100644 index 00000000..869a7b00 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getOptsMixedLongShort.optionsAndArguments..st @@ -0,0 +1,29 @@ +parsing +getOptsMixedLongShort: mixedOptionSpecs optionsAndArguments: optsAndArgsBlock + "mixedOptionSpecs is an array of option specs, for example: + + {#('directory' $d #'required'). + #('class' nil #'none'). + #('package' nil #'none'). + #('category' nil #'required')} + + each subarray consists of the long-option-name, short-option-character, + [required|none|optional] +" + + | longOptionsSpec shortOptionAliases | + longOptionsSpec := Dictionary new. + shortOptionAliases := Dictionary new. + mixedOptionSpecs + do: [ :spec | + | optionName shortOptionCharacter optionValueSpec | + optionName := spec at: 1. + shortOptionCharacter := spec at: 2. + optionValueSpec := spec at: 3. + longOptionsSpec at: optionName put: optionValueSpec. + shortOptionCharacter + ifNotNil: [ shortOptionAliases at: shortOptionCharacter put: optionName ] ]. + ^ self + getOptsLong: longOptionsSpec + short: shortOptionAliases + optionsAndArguments: optsAndArgsBlock \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandLongOpts.short.do.argsDo..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandLongOpts.short.do.argsDo..st new file mode 100644 index 00000000..bd7c160f --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandLongOpts.short.do.argsDo..st @@ -0,0 +1,13 @@ +obsolete +getSubCommandLongOpts: optionSpec short: shortOptionAliases do: optionBlock argsDo: argBlock + | optionStream optionString | + optionString := commandLine + copyFrom: self subCommandArgPtr + to: commandLine size. + optionStream := ReadStream on: optionString. + TDCommandGetOpts + getOptsLongFor: optionStream + longOptionSpec: optionSpec + shortOptionAliases: shortOptionAliases + do: optionBlock + nonOptionsDo: argBlock \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandOpts.do.argsDo..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandOpts.do.argsDo..st new file mode 100644 index 00000000..1455fad3 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandOpts.do.argsDo..st @@ -0,0 +1,12 @@ +obsolete +getSubCommandOpts: optionSpec do: optionBlock argsDo: argBlock + | optionStream optionString | + optionString := commandLine + copyFrom: self subCommandArgPtr + to: commandLine size. + optionStream := ReadStream on: optionString. + TDCommandGetOpts + getOptsFor: optionStream + spec: optionSpec + do: optionBlock + nonOptionsDo: argBlock \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandOpts.optionsAndArguments..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandOpts.optionsAndArguments..st new file mode 100644 index 00000000..787687f7 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/getSubCommandOpts.optionsAndArguments..st @@ -0,0 +1,10 @@ +obsolete +getSubCommandOpts: optionSpec optionsAndArguments: optsAndArgsBlock + | options args | + options := Dictionary new. + args := OrderedCollection new. + self + getSubCommandOpts: optionSpec + do: [ :option :optionArg | options at: option asString put: optionArg ] + argsDo: [ :arg | args add: arg ]. + optsAndArgsBlock value: options value: args \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/hasSubCommand..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/hasSubCommand..st new file mode 100644 index 00000000..5d2a9d4b --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/hasSubCommand..st @@ -0,0 +1,3 @@ +obsolete +hasSubCommand: aBool + hasSubCommand := aBool \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/hasSubCommand.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/hasSubCommand.st new file mode 100644 index 00000000..adbd6aee --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/hasSubCommand.st @@ -0,0 +1,4 @@ +obsolete +hasSubCommand + hasSubCommand ifNil: [ hasSubCommand := false ]. + ^ hasSubCommand \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/parseMixedLongShortOpts..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/parseMixedLongShortOpts..st new file mode 100644 index 00000000..68fd8f15 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/parseMixedLongShortOpts..st @@ -0,0 +1,27 @@ +private +parseMixedLongShortOpts: mixedOptionSpecs + "mixedOptionSpecs is an array of option specs, for example: + + {#('directory' $d #'required'). + #('class' nil #'none'). + #('package' nil #'none'). + #('category' nil #'required')} + + each subarray consists of the long-option-name, short-option-character, + [required|none|optional] +" + + | longOptionsSpec shortOptionAliases | + longOptionsSpec := Dictionary new. + shortOptionAliases := Dictionary new. + mixedOptionSpecs + do: [ :spec | + | optionName shortOptionCharacter optionValueSpec | + optionName := spec at: 1. + shortOptionCharacter := spec at: 2. + optionValueSpec := spec at: 3. + longOptionsSpec at: optionName put: optionValueSpec. + shortOptionCharacter + ifNotNil: [ shortOptionAliases at: shortOptionCharacter put: optionName ] ]. + ^ {longOptionsSpec. + shortOptionAliases} \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/printOn..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/printOn..st new file mode 100644 index 00000000..bdb6f3e0 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/printOn..st @@ -0,0 +1,3 @@ +printing +printOn: aStream + aStream nextPutAll: self class name asString , '(' , self commandLine printString , ')' \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/rawTokens.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/rawTokens.st new file mode 100644 index 00000000..28a26a57 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/rawTokens.st @@ -0,0 +1,4 @@ +private +rawTokens + tokens ifNil: [ tokens := self tokenize: self commandLine ]. + ^ tokens \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/redirectTarget..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/redirectTarget..st new file mode 100644 index 00000000..d72684e3 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/redirectTarget..st @@ -0,0 +1,3 @@ +private +redirectTarget: aString + redirectTarget := aString \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/redirectTarget.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/redirectTarget.st new file mode 100644 index 00000000..ef1acffc --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/redirectTarget.st @@ -0,0 +1,3 @@ +accessing +redirectTarget + ^ redirectTarget \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/subCommand.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/subCommand.st new file mode 100644 index 00000000..98d00386 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/subCommand.st @@ -0,0 +1,5 @@ +accessing +subCommand + self rawTokens size < 2 + ifTrue: [ TodeCommandError signal: 'expected a subcommand' ]. + ^ self rawTokens at: 2 \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/subCommandArgPtr.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/subCommandArgPtr.st new file mode 100644 index 00000000..1aba398e --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/subCommandArgPtr.st @@ -0,0 +1,3 @@ +obsolete +subCommandArgPtr + ^ self argPtrs at: 2 \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokenize..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokenize..st new file mode 100644 index 00000000..85825596 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokenize..st @@ -0,0 +1,40 @@ +private +tokenize: aString + | list token final escaped delimited stream count | + list := OrderedCollection new. + argPtrs := OrderedCollection new. + token := WriteStream on: String new. + escaped := false. + delimited := false. + stream := ReadStream on: aString. + count := 0. + [ stream atEnd ] + whileFalse: [ + | char | + char := stream next. + count := count + 1. + escaped + ifTrue: [ + char = $` + ifTrue: [ escaped := false ] + ifFalse: [ token nextPut: char ] ] + ifFalse: [ + char == Character space + ifTrue: [ + delimited + ifFalse: [ + list add: token contents. + argPtrs add: count. + token := WriteStream on: String new ]. + delimited := true ] + ifFalse: [ + delimited := false. + char = $` + ifTrue: [ escaped := true ] + ifFalse: [ token nextPut: char ] ] ] ]. + final := token contents. + final isEmpty + ifFalse: [ + list add: final. + argPtrs add: count + 1 ]. + ^ list \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokens..st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokens..st new file mode 100644 index 00000000..45d0533c --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokens..st @@ -0,0 +1,3 @@ +private +tokens: aCollection + tokens := aCollection \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokens.st b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokens.st new file mode 100644 index 00000000..c92d8ba6 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/instance/tokens.st @@ -0,0 +1,7 @@ +parsing +tokens + ^ self hasSubCommand + ifTrue: [ + self rawTokens. + tokens copyFrom: 2 to: tokens size ] + ifFalse: [ self rawTokens ] \ No newline at end of file diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/methodProperties.json b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/methodProperties.json new file mode 100644 index 00000000..16275a3a --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/methodProperties.json @@ -0,0 +1,37 @@ +{ + "class" : { + "commandLine:redirectTarget:" : "dkh 5/16/2013 18:15", + "fromStream:forEachCommand:" : "dkh 12/17/2014 16:33", + "fromStream:selectLine:forEachCommand:" : "dkh 11/03/2015 18:09", + "isolate:" : "dkh 12/17/2014 15:27", + "line:forEachCommand:" : "dkh 12/17/2014 15:32", + "scan:delim:" : "dkh 05/20/2013 22:22" }, + "instance" : { + "argPtrs" : "dkh 11/10/2013 06:57", + "command" : "dkh 11/10/2013 10:28", + "commandArgPtr" : "dkh 11/10/2013 06:57", + "commandLine" : "dkh 5/16/2013 16:00", + "commandLine:" : "dkh 11/22/2013 16:28", + "getCommandLongOpts:short:do:argsDo:" : "dkh 11/11/2013 16:42", + "getCommandOpts:do:argsDo:" : "dkh 11/10/2013 07:31", + "getCommandOpts:optionsAndArguments:" : "dkh 03/30/2014 09:51", + "getOpts:optionsAndArguments:" : "dkh 04/18/2014 08:13", + "getOpts:subOpts:optionsAndArguments:" : "dkh 04/18/2014 08:12", + "getOptsLong:optionsAndArguments:" : "dkh 11/11/2013 16:49", + "getOptsLong:short:optionsAndArguments:" : "dkh 04/18/2014 08:13", + "getOptsMixedLongShort:optionsAndArguments:" : "dkh 11/11/2013 16:47", + "getSubCommandLongOpts:short:do:argsDo:" : "dkh 11/11/2013 16:43", + "getSubCommandOpts:do:argsDo:" : "dkh 11/10/2013 07:33", + "getSubCommandOpts:optionsAndArguments:" : "dkh 11/10/2013 07:42", + "hasSubCommand" : "dkh 11/10/2013 09:50", + "hasSubCommand:" : "dkh 11/10/2013 09:50", + "parseMixedLongShortOpts:" : "dkh 11/11/2013 12:40", + "printOn:" : "dkh 1/11/2014 11:20", + "rawTokens" : "dkh 11/22/2013 16:27", + "redirectTarget" : "dkh 5/16/2013 16:01", + "redirectTarget:" : "dkh 11/10/2013 06:40", + "subCommand" : "dkh 03/30/2014 08:07", + "subCommandArgPtr" : "dkh 11/10/2013 06:58", + "tokenize:" : "dkh 11/11/2013 20:58", + "tokens" : "dkh 11/10/2013 10:01", + "tokens:" : "dkh 5/16/2013 19:22" } } diff --git a/src/GsDevKit_stones-Tode.package/TDCommandLine.class/properties.json b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/properties.json new file mode 100644 index 00000000..5a33fda7 --- /dev/null +++ b/src/GsDevKit_stones-Tode.package/TDCommandLine.class/properties.json @@ -0,0 +1,18 @@ +{ + "category" : "Topez-Common-Core", + "classinstvars" : [ + ], + "classvars" : [ + ], + "commentStamp" : "", + "instvars" : [ + "commandLine", + "redirectTarget", + "tokens", + "argPtrs", + "hasSubCommand" ], + "name" : "TDCommandLine", + "pools" : [ + ], + "super" : "Object", + "type" : "normal" }