[Gambas-devel] please, need help with gb.option
chintan rao
chintanraoh at ...176...
Tue Jun 3 16:46:26 CEST 2008
Hi,
Documentation for this is not currently available. Currently I don't
have time as I am not 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
On Tue, Jun 3, 2008 at 2:41 PM, <rospolosco at ...176...> wrote:
> Hi Chintan
>
> Please, could you provide a little code to show me
> how to use gb.option component of Gambas.
>
> I need an example application that accepts options
> "-a -b -c" and print their arguments. I mean:
>
> example.gambas -a test -b foo -c bar
>
> result on console:
>
> "-a" argument is "test"
> "-b" argument is "foo"
> "-c" argument is "bar"
>
> Then, I would like to know if with gb.option an option
> could take multiple args. i.e: -a foo bar -b test
>
> I googled a lot and searched in the Gambas documentation,
> but I can't find any example. Thanks.
>
> Regards,
>
> Stefano
>
More information about the Devel
mailing list