get long options
Utility Library
This function identifies all long options specified as command line parameters when starting a B4P program and assigns their names and values into a global
variable called long options[], provided at least one such long option has been identified.
Long options are defined as command line options which begin with two consecutive minus signs (--) followed by an option name.
The option name may optionally be completed with an option value, using an equal sign followd by a string or numeric value.
By default, the values are strings, but may be converted to boolean (if "true" or "false"), dates (if "YYYY-MM-DD", "HH:MM:SS" or "YYYY-MM-DD HH:MM:SS"),
or numerals (if number provided). If you need to know the ordering of the options, then check the command line arguments directly.
Example | Member Name | Member Value |
---|---|---|
--test | long options[test] | void |
--row=1 col="2" | long options[row] long options[col] | 1 2 (both numerals) |
--date="2020-12-31" | long options[date] | 2020-12-31 (date format) |
--ans1=true ans2="false" | long options[ans1] long options[ans2] | true false (both Boolean types) |
--t1=Hi --t2="He He" | long options[t1] long options[t2] | "Hi" "He He" (both strings) |
Please note that short options (e.b. '-a') are entirely reserved for starting and execution options provided by the B4P Data Engine and
they will not be visible to the B4P programs.
Under normal conditions, the 'Utility Library' is loaded automatically, so no 'include(...)' call is needed.
0
Type | Description |
---|---|
numeral | Number of long options found If no long options are provided, then 0 is returned, and the variable long options[] will not be created. |
program file[] = "Example_Program.b4p"; // The own program will be called recursively.
// Rename this filename to name of this file
count[] = get long options(); // Identify long options with the best yield in the market
if (count[] == 0) // Program starts here
{
echo("Test 1: Start B4P program using shell command with some long options", new line);
system("b4p -x " + program file[] + ' --facts --decision=false --value=25.1 --time="18:30:15" ' );
echo("Test 2: Start B4P program using 'start()'");
start( program file[], '--myths', '--decision=true', '--value=30', '--name="Jim"', '--date=2021-02-21' );
}
else // This part is executed in teh recursive call.
{
echo("Number of long options found: ", count[] );
see( long options[] );
echo(new line);
}
Test 1: Start B4P program using shell command with some long options
B4P - Beyond Former Performance
_______________________________________________________________________________
Version 11.00 'Sydney Opera House' (2024-10-20)
Copyright (C) 2012..2024 Georg zur Bonsen, all rights reserved.
Licensed (local machine) with standard privileges for Alstom (Schweiz) AG.
Number of long options found: 4
long options[] [Void] (void,full access)
decision false (boolean,full access)
facts [Void] (void,full access)
time 18:30:15 "18:30:15" (date,full access)
value 25.1 "25.1" (numeral,full access)
Test 2: Start B4P program using 'start()'
Number of long options found: 5
long options[] [Void] (void,full access)
date 2021-02-21 "2021-02-21" (date,full access)
decision true (boolean,full access)
myths [Void] (void,full access)
name "Jim" (quoted string,full access)
value 30 "30" (numeral,full access)