Update to gb.args

Feel free to talk about non programming issues here.
Post Reply
User avatar
BruceSteers
Posts: 476
Joined: Thursday 23rd July 2020 5:20pm

Update to gb.args

Post by BruceSteers » Wednesday 24th February 2021 1:55am

Hi all.

I made some changes to gb.args that have now been merged to the master branch.

New features..

Args.Get() now has an additional final parameter "Default"
Args.Get(ShortName As String, LongName As String, Optional Description As String, Optional ArgName As String, Optional Default As String) As String

works just like Settings[Keyname,Default] and returns the given default string if not found.

Also it is now possible to override the -V --version and -h --help flags, meaning....

If you use Args.Has() to check for -V or -h between the calls to Arg.Begin and Args End then your call will override the default behaviour.

This could be useful if you want to customise the version string.
So you could do this...

Args.Begin

If Args.Has("v", "version", "my alternative version msg for help") Then

 Print Application.Version & Iif(bAppIsBeta, "(BETA)", "(STABLE)")

Endif

Args.End

Before I added the override you could still do that but help text would display both the default version help message and the custom one (although it would use the custom one it was confusing)

Now if -V Arg Has been checked the default message is suppressed.

The same goes for --help
If you use Args.Has() to check -h --help then the default help message is suppressed and you can display your own with the same method as -V above.
If you wish to display the original help message then you can do so with the following new command...

Args.HelpText(Optional PrintText As Boolean) As String

That command can be called any time after Args.Begin or after Args.End but not before Args.Begin
It returns the original --help message as a string and will Print it to stdout if the optional arg is true

Example...

Args.Begin

  If Args.Has("h", "help", "custom help") Then

    Print "I can add a message header to the help here....."

    Args.HelpText(True) ' Print the help message.

    Print "I can add a footer here..."

  Endif

Args.End

Hopefully that may be useful for others too.

All the best
Wishing well
Bruce

If at first you don't succeed , try it differently.

Post Reply