[Gambas-user] gb.args - a question

Tobias Boege taboege at ...626...
Sat Feb 16 14:51:07 CET 2013


On Sat, 16 Feb 2013, Willy Raets wrote:
> Okay Bruce,
> 
> Thanks again, you got me on the right track and I got it solved showing
> me about info without launching the application.
> 
> Here is how I did it:
> 
> Public Sub Main()
>   
>   Dim bAOption As Boolean
>   Args.Begin(Application.Name & " <options>")
>   bAOption = Args.Has("a", "about", "Display About")
>   Args.End()
>   If bAOption Then
>     Print "Application to test gb.args"
>   Else
>     FMain.Show
>   Endif
>   
> End
> 
> When doing <appname> -h it now correctly states "Display About" for help
> with -a and --about
> When doing <appname> -a it now correctly returns "Application to test
> gb.args" (without the GUI application getting launched)
> 
> Perfect, I think I'm slowly beginning to get a grasp at it.
> Public Sub Main()
>   
>   Dim bAOption As Boolean
>   Args.Begin(Application.Name & " <options>")
>   bAOption = Args.Has("a", "about", "Display About")
>   Args.End()
>   If bAOption Then
>     Print "Application to test gb.args"
>   Else
>     FMain.Show
>   Endif
>   
> End
> 
> Feel free to use this example in documentation if you like (or an
> adapted version for that matter). An example tells a whole lot more in
> way less time than studying the documentation, try, fail, study
> documentation, try, fail, study documentation, try, fail, search google,
> find nothing, post on mailing list, get answer, try, fail, study
> documentation, try, fail and so on... :)
> 
> Thanks again Bruce for the spark...

Since gb.args is written in Gambas and implements -V and -h, it is an
example itself. Look into comp/src/gb.args/.src/Args.module. It is done with
those options there the same way inside Args.End(). I _believe_ that you can
even save the bAOption variable by using: If Args.Has(...) Then Print "..."
before calling Args.End().

Regards,
Tobi




More information about the User mailing list