CmdLineOption.st
author Claus Gittinger <cg@exept.de>
Wed, 14 Sep 2011 15:48:16 +0200
changeset 13695 278e1b963c87
parent 13482 769530195abb
child 13938 c7c6a5463841
permissions -rw-r--r--
oops

"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libbasic' }"

Object subclass:#CmdLineOption
	instanceVariableNames:'action description short long'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Support-Command line'
!

!CmdLineOption class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
              All Rights Reserved

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
! !

!CmdLineOption methodsFor:'accessing'!

action
    ^ action

    "Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

action:aBlockOrMessageSend

    aBlockOrMessageSend numArgs > 1 ifTrue:
        [CmdLineOptionError raiseErrorString: 'Action must be zero-or-one arg block/message send'].    
    action := aBlockOrMessageSend.

    "Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 16-06-2009 / 15:46:54 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

description
    ^ description

    "Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

description:aString
    description := aString.

    "Created: / 28-01-2009 / 11:49:55 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

long
    ^ long
!

long:aString
    long := aString.
!

short
    ^ short
!

short:aCharacterOrString

    (aCharacterOrString isCharacter 
        and:[aCharacterOrString isAlphaNumeric])
            ifTrue:[short := aCharacterOrString]
            ifFalse:[self error: 'short option name should be alphanumeric character']

    "Modified: / 29-05-2009 / 16:05:46 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!CmdLineOption methodsFor:'printing & storing'!

printOn: stream

    super printOn: stream.
    stream nextPut:$(.
    short ifNotNil:[stream nextPut: $-; nextPut: short].
    (short notNil and: [long notNil]) ifTrue:[stream nextPut:$|].
    long ifNotNil:[stream nextPut: $-;  nextPut: $-; nextPutAll: long].
    stream nextPut:$)

    "Created: / 08-06-2009 / 14:48:59 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!CmdLineOption methodsFor:'processing'!

process

    action value

    "Created: / 08-06-2009 / 14:35:01 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

process: value

    action value: value

    "Created: / 08-06-2009 / 14:35:08 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!CmdLineOption methodsFor:'queries'!

hasParam

    ^action numArgs = 1

    "Created: / 08-06-2009 / 13:45:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!CmdLineOption class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libbasic/CmdLineOption.st,v 1.2 2011-07-03 15:06:59 cg Exp $'
!

version_SVN
    ^ '§Id: CmdLineOption.st,v 1.1 2011/06/28 10:54:52 vrany Exp §'
! !