[Gambas-user] New component: gb.args

Bruce bbruen at ...2308...
Fri Oct 19 12:19:28 CEST 2012


On Tue, 2012-10-16 at 02:06 +0200, Benoît Minisini wrote:
> Hi,
> 
> In the last revision, I added a new component 'gb.args', which replaces 
> the unmaintained 'gb.option'. By the way, does anyone use 'gb.option'?
> 
> The goal of this component made in Gambas is analyzing the command-line 
> arguments and return the value of options.
> 
> It works like that:
> 
> ' Start the analyze : UsageString is an optional string describing
> ' the global syntax of the command with its name.
> 
> Args.Begin(UsageString)
> 
> ' This method returns if an option is present or not, with the form
> ' "-s" or "--long"
> 
> Args.Has("s", "long", ("description"))
> 
> ' This method defines an option that takes one string argument, and
> ' returns it.
> 
> Args.Get("s", "long", ("description"), ("argument name"))
> 
> ' This method defines an option that takes one integer argument, and
> ' returns it. The argument can be prefixed by "0x" for an hexadecimal
> ' number.
> 
> Args.GetInteger("s", "long", ("description"), ("argument name"),
>    DefaultValue)
> 
> ' This method ends the analyze, and returns all extra arguments (that
> ' usually are file paths to process). The arguments are returned into
> ' a String array.
> 
> Args.End()
> 
> Moreover, the End() method automatically handles:
> 
> - An '-h/--help' option that prints the program usage by using the usage 
> string sent to the Begin() function and all option descriptions.
> 
> - A '-V/--version' option that prints the program version.
> 
> Tell me what you think about that component!
> 
> Regards,
> 
Hi Benoît,

I've given this (gb.args) a bit of a try and I quite like it.  One
question arose though.

We have some components and libraries that search Application.Args for
an occurrence of a command line arg.  For example one component, our
central db connection manager looks for a "--reconfiguredb" CL option
that allows/forces the user to re-enter the database connection
parameters when we have released a new version of the database.  (So if
we move from auctions030108 to auctions030109 on our central database,
we let them know that they have to run our main app with the
--reconfiguredb option.)

Here's the question.  It would be nice, or to put it another way, is it
possible to declare the Args.Has("","--reconfiguredb", "Reset the
central database connection") in the component or do we have to do it in
any/all the apps that use that component?

regards
Bruce







More information about the User mailing list