[Gambas-user] New component: gb.args

Benoît Minisini gambas at ...1...
Tue Oct 16 02:06:56 CEST 2012


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,

-- 
Benoît Minisini




More information about the User mailing list