Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation from source code
Components
gb
gb.args
Args
Abort
Begin
End
Get
GetFloat
GetInteger
Has
gb.cairo
gb.chart
gb.clipper
gb.complex
gb.compress
gb.crypt
gb.data
gb.db
gb.db.form
gb.db.mysql
gb.db.odbc
gb.db.postgresql
gb.db.sqlite2
gb.db.sqlite3
gb.db2
gb.db2.form
gb.dbus
gb.dbus.trayicon
gb.debug
gb.desktop
gb.desktop.gnome.keyring
gb.desktop.x11
gb.eval
gb.eval.highlight
gb.form
gb.form.dialog
gb.form.editor
gb.form.htmlview
gb.form.mdi
gb.form.print
gb.form.stock
gb.form.terminal
gb.gmp
gb.gsl
gb.gtk
gb.gtk.opengl
gb.gtk3
gb.gtk3.opengl
gb.gtk3.webview
gb.gui
gb.gui.opengl
gb.gui.qt
gb.gui.qt.ext
gb.gui.qt.opengl
gb.gui.qt.webkit
gb.gui.trayicon
gb.gui.webview
gb.hash
gb.highlight
gb.image
gb.image.effect
gb.image.imlib
gb.image.io
gb.inotify
gb.jit
gb.libxml
gb.logging
gb.map
gb.markdown
gb.media
gb.media.form
gb.memcached
gb.mime
gb.mongodb
gb.mysql
gb.ncurses
gb.net
gb.net.curl
gb.net.pop3
gb.net.smtp
gb.openal
gb.opengl
gb.opengl.glsl
gb.opengl.glu
gb.opengl.sge
gb.openssl
gb.option
gb.pcre
gb.pdf
gb.poppler
gb.qt4
gb.qt4.ext
gb.qt4.opengl
gb.qt4.webkit
gb.qt4.webview
gb.qt5
gb.qt5.ext
gb.qt5.opengl
gb.qt5.webkit
gb.qt5.webview
gb.qt6
gb.qt6.ext
gb.qt6.opengl
gb.qt6.webview
gb.report
gb.report2
gb.scanner
gb.sdl
gb.sdl.sound
gb.sdl2
gb.sdl2.audio
gb.settings
gb.signal
gb.term
gb.test
gb.util
gb.util.web
gb.v4l
gb.vb
gb.web
gb.web.feed
gb.web.form
gb.web.gui
gb.xml
gb.xml.html
gb.xml.rpc
gb.xml.xslt
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

Args (gb.args)

This class reimplements Args in gb.

This class is static.

This class acts like a read-only static array.

This class is statically enumerable with the FOR EACH keyword.

Static properties
Abort   Return or set whether the program aborts or raises an error when an Args method fails.

Inherited static properties
All   Return a copy of the process arguments as a string array.
Count   Return the number of command line arguments.
Max   Returns Args.Count - 1

Static methods
Begin   Start the program argument analysis.
End   Terminate the program argument analysis, and return all arguments that could not be interpreted as an option or an option argument.
Get   Define an option that takes one string argument, and return it.
GetFloat   Define an option that takes one floating point number argument, and return it.
GetInteger   Define an option that takes one integer number argument, and return it.
Has   Define an option that takes no argument, and return if it has been specified.
HelpText   Get the default help message.
Must be used after Args.Begin() Returns the message text and will Print to stdout if boolean arg PrintText is True.

Inherited static methods
Copy   Return a copy of the argument list as a string array.

This class analyses the arguments of the current process.

It allows you to:
  • Extract options from the program arguments.

  • Automatically handle --version and --help options.

  • Return non-options as arguments.

Use the Begin method to start the option analysis and the End method to terminate it.

This class will automatically print help, usage and version messages to the standard output if -h or -V are not checked manually by the programmer.

If an error occurs, the program quits with the exit code 1.

Since 3.16.4

Set Args.Abort = False to override quitting and handle errors yourself.

Since 3.16

You can use Args.Has() to check for -V --version or -h --help manually then the default output will be suppressed and your application will not quit.

This is useful to display your own custom help or version message.

Args.HelpText() can be used to get or print the original help text if you are handling the -h manually but it MUST ONLY be called AFTER calling Args.End() or the help texts will not yet have been constructed.

Public Sub Main()

  Dim bHelp As Boolean

  Args.Begin(Application.Name & " <options>")
  bHelp = Args.Has("h", "help", "Display a customised help message")
  Args.End()

  If bHelp Then

    Args.HelpText(True) ' Print standard help text to terminal
    Print "Additional Help message can be written here"

    ' Now exit the program as overriding the -h argument will stop it automatically quitting.
    Quit

  Endif

End