[Gambas-devel] gb.option What it is used for?
Stefano Palmeri
rospolosco at ...29...
Thu Sep 25 16:49:28 CEST 2008
Il giovedì 25 settembre 2008 14:20:01 David Villalobos Cambronero ha scritto:
> Hi all, Does anybody know what gb.option is used for? How can I use it?
> Maybe an small example?
>
> Regards
>
>
> --
> David
>
Hi this is the message that the author of gb.option sent me some time ago.
You can find it even in developers-list archives. Benoit, don't you think
it's gonna be useful to add it in Gambas documentation, do you?
--------8X--------------------------------
Hi,
Documentation for this is not currently available. Currently I don't
have time as I am involved in some other project. But I will be
writing one as soon as I am free. i hope I will be free soon.
Tell me if you find this interface annoying. I will change it when I
have time to do so
I think I must make the thing simpler.
You declare the opt object as
DIM opt AS NEW GetOptions("la:b:c:")
At this point you may really feel that GetOptions must be static class
( I don't remember why made no static. This component right now is in
beta stage :) . )
if colon (ie ":") is specified after a character c, it means that that
option must be be followed by an argument opt[c] will be the argument.
if ":" is not specified it will be a opt[c] will 0 or 1
also opt["?"] is 1 if there is an error in specifying the command line
arguments
PUBLIC SUB Main()
DIM opt AS NEW GetOptions("la:b:c:")
IF opt["?"] = 1
PRINT "error parsing the arguments"
ENDIF
IF opt["l"] = 1
PRINT "found option l"
ENDIF
IF opt["a"] <> 1 AND opt["a"] <> 0
PRINT opt["a"]
ENDIF
IF opt["b"] <> 1 AND opt["a"] <> 0
PRINT opt["b"]
ENDIF
IF opt["c"] <> 1 AND opt["c"] <> 0
PRINT opt["c"]
ENDIF
END
Also there is a way in which you can list the opts one by one.
' Gambas module file
PUBLIC SUB Main()
DIM opt AS NEW GetOptions("h:elo")
DIM c AS String
PRINT "command line args:\"" & opt.CommandLineArgs.Join(" ") & "\""
WHILE TRUE
c = opt.NextValidOption()
PRINT opt.OptionArgument()
IF c = ""
BREAK
ENDIF
SELECT CASE c
CASE "h"
PRINT "option h" & " the corresponding argument is\"" &
opt.OptionArgument() & "\""
CASE "e"
PRINT "option e"
CASE "l"
PRINT "option l"
CASE "o"
PRINT "option o"
CASE "?"
PRINT "error parsing the arguments"
PRINT "invalid option " & opt.GetErrorOption()
BREAK
CASE ":"
PRINT "error parsing the arguments"
PRINT "no arguments to option " & opt.GetErrorOption()
END SELECT
WEND
IF opt.RestOfArgs().Count <> 0
PRINT "Rest of the arguments are \"" & opt.RestOfArgs().Join(" ")&
"\""
ENDIF
END
>
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge Build the coolest Linux based applications with Moblin SDK & win
> great prizes Grand prize is a trip for two to an Open Source event anywhere
> in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel
More information about the Devel
mailing list