-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleArguments_Manual.pb
79 lines (56 loc) · 2.04 KB
/
SimpleArguments_Manual.pb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;{- Code Header
; ==- Basic Info -================================
; Name: SimpleArguments_Manual.pb
; Version: N/A
; Author: Herwin Bozet
;
; ==- Description -===============================
; This example will show you how to manually declare, register, parse and read arguments.
; The following args are available: [-h|--help] [-a] [--test] [-d|--data <TEXT>]
;
; Recommend arguments: -h -a --test -d "Hello World !"
;
;}
;-> Compiler Directives
EnableExplicit
XIncludeFile "../Arguments.pbi"
;-> Initialization
Arguments::Init()
;-> Argument declaration
Define *OptHelp.Arguments::Option = Arguments::CreateOption('h', "help", "Help text !")
Define *OptAll.Arguments::Option = Arguments::CreateOption('a', #Null$, "All stuff")
Define *OptTest.Arguments::Option = Arguments::CreateOption(#Null, "test", "test flag")
Define *OptData.Arguments::Option = Arguments::CreateOption('d', "data", "Data input", Arguments::#Option_HasValue)
If (Not *OptHelp) Or (Not *OptAll) Or (Not *OptTest) Or (Not *OptData)
Debug "Failed to create one or more options !"
End 1
EndIf
If (Not Arguments::RegisterOption(*OptHelp)) Or
(Not Arguments::RegisterOption(*OptAll)) Or
(Not Arguments::RegisterOption(*OptTest)) Or
(Not Arguments::RegisterOption(*OptData))
Debug "Failed to register one or more options !"
End 2
EndIf
;-> Argument parsing
Define LastParserError = Arguments::ParseArguments()
If LastParserError <> Arguments::#Error_None
Debug "An error occured while parsing the arguments !"
Debug LastParserError
End 3
EndIf
;-> Taking actions
If *OptHelp\WasUsed
; Does not care if -h or --help was used
Debug "Printing the help text..."
EndIf
If *OptData\WasUsed
Debug "Data was given !"
; For-loop technically not required if the option is not declared with Arguments::#Option_HasMultipleValue
; since an error will be thrown when multiple values are given to an option with only Arguments::#Option_HasValue.
ForEach *OptData\Arguments()
Debug "> " + *OptData\Arguments()
Next
EndIf
;-> Cleaning up
Arguments::Finish()