Commit 96ebc591 authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Args.Abort is a new property that tells if the program aborts or raises an...

Args.Abort is a new property that tells if the program aborts or raises an error when an Args method fails. The property is TRUE by default.

[GB.ARGS]
* NEW: Args.Abort is a new property that tells if the program aborts or raises an error when an Args method fails. The property is TRUE by default.
parent 88494353
Pipeline #360658655 passed with stage
in 26 minutes and 21 seconds
[Component]
Key=gb.args
Version=3.15.90
Version=3.16.90
Authors=Benoît Minisini
# Gambas Project File 3.0
Title=gb.args
Startup=MMain
Version=3.15.90
Version=3.16.90
VersionFile=1
Authors="Benoît Minisini"
Arguments=[["-V","-p","toto","zozo","-s","512","--","project"],["--help"]]
CurrentArgumentList=["--help"]
CurrentArgumentList=["-zop"]
TabSize=2
Translate=1
Language=en
......
......@@ -2,6 +2,8 @@
Export
Property Abort As Boolean Use $bAbort = True
Private $cArg As Collection
Private $aRest As Integer[]
Private $aHelp As String[]
......@@ -9,11 +11,19 @@ Private $sUsage As String
Private $bManualVersion As Boolean
Private $bManualHelp As Boolean
Private Sub Abort(sErr As String)
Private Sub DoAbort(sErr As String)
Error Application.Name; ": "; sErr
Quit 1
If $bAbort Then
Error Application.Name; ": "; sErr
Quit 1
Else
Error.Raise(sErr)
Endif
End
......@@ -88,7 +98,7 @@ Public Sub End() As String[]
If $cArg.Count Then
For Each $cArg
Abort(Subst(("unknown option: &1"), $cArg.Key))
DoAbort(Subst(("unknown option: &1"), $cArg.Key))
Next
Endif
......@@ -105,7 +115,7 @@ End
Public Sub HelpText(Optional PrintText As Boolean) As String
If Not $aHelp Then
Abort(("Error: Args.Helptext() must be called after the command Args.Begin()"))
DoAbort(("Error: Args.Helptext() must be called after the command Args.Begin()"))
Endif
Dim sVar As String
......@@ -195,10 +205,10 @@ Public Sub Get(ShortName As String, LongName As String, Optional Description As
If IsNull(vShort) And If IsNull(vLong) Then Return {Default}
If TypeOf(vShort) = gb.Boolean Then Abort(Subst("argument missing for option -&1", ShortName))
If TypeOf(vLong) = gb.Boolean Then Abort(Subst("argument missing for option --&1", LongName))
If TypeOf(vShort) = gb.Boolean Then DoAbort(Subst("argument missing for option -&1", ShortName))
If TypeOf(vLong) = gb.Boolean Then DoAbort(Subst("argument missing for option --&1", LongName))
If vShort And If vLong Then Abort(Subst("argument specified twice for option -&1", ShortName))
If vShort And If vLong Then DoAbort(Subst("argument specified twice for option -&1", ShortName))
$cArg["-" & ShortName] = Null
$cArg["--" & LongName] = Null
......@@ -226,7 +236,7 @@ Public Sub GetInteger(ShortName As String, LongName As String, Optional Descript
Try iVal = Val("&H" & sVal)
If Not Error Then Return iVal
Endif
If Not IsInteger(sVal) Then Abort(Subst("option &1 needs an integer argument"), GetKey(ShortName, LongName))
If Not IsInteger(sVal) Then DoAbort(Subst("option &1 needs an integer argument"), GetKey(ShortName, LongName))
Return CInt(sVal)
End
......@@ -238,9 +248,8 @@ Public Sub GetFloat(ShortName As String, LongName As String, Optional Descriptio
If Not sVal Then Return {Default}
Try fVal = CFloat(sVal)
If Error Then Abort(Subst("option &1 needs a floating point number argument"), GetKey(ShortName, LongName))
If Error Then DoAbort(Subst("option &1 needs a floating point number argument"), GetKey(ShortName, LongName))
Return fVal
End
\ No newline at end of file
......@@ -4,6 +4,8 @@ Public Sub Main()
Dim iStack As Integer
Args.Abort = False
Args.Begin() '"Usage: gbx3 <options> <project>\n gbx3 -e <expression>")
Args.Has("k", "no-unload", "Do not unload shared libraries")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment