ug4
command_line_util.lua File Reference

Functions

function util CheckAndPrintHelp (desc)
 
function util CheckForParam (name)
 
function util CheckOptionsType (name, options, atype)
 
function util CheckOptionsValue (name, value, options)
 
function util ConcatOptions (options)
 
function util GetCommandLine ()
 
function GetMinLevenshteinDistanceOfIndex (str, list)
 
function GetMinLevenshteinDistanceOfValue (str, list)
 
function util GetParam (name, default, description, options, atype)
 
function util GetParamBool (name, default, description)
 
function util GetParamFromList (name, default, list)
 
function util GetParamNumber (name, default, description, options)
 
function util GetParamNumberArray (name, default, description)
 
function util GetUniqueFilenameFromCommandLine ()
 
function util GetUserParameters (params, descriptors)
 
function util HasParamOption (name, description)
 
function util PrintArguments ()
 
function util PrintHelp ()
 
function util PrintIgnoredArguments ()
 
function StrOrNil (s)
 

Variables

parameterString ex = ""
 Executes the specified script. More...
 
parameterString logtofile = ""
 Output will be written to the specified file. More...
 
parameterBool noquit
 Runs the interactive shell after specified script;. More...
 
parameterBool noterm
 Terminal logging will be disabled;. More...
 
parameterNumber outproc = 0
 Sets the output-proc to id. More...
 
parameterBool profile
 Shows profile-output when the application terminates;. More...
 

Function Documentation

◆ CheckAndPrintHelp()

function util CheckAndPrintHelp ( desc  )

calls util.PrintHelp() and exits if HasParamOption("-help")

Parameters
optionaldescription of the script

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :369-376

function util.CheckAndPrintHelp(desc)
if util.HasParamOption("-help", "print this help") then
if desc ~= nil then print(desc) end
print()
util.PrintHelp()
exit()
end
end
function util PrintHelp()
function table print(data, style)

◆ CheckForParam()

function util CheckForParam ( name  )

util.CheckForParam Checks whether a paramneter was specified in the command line

Parameters
nameof the parameter to search for in argv
Returns
true if the parameter was found, false if not

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :316-324

function util.CheckForParam(name)
for i = 1, ugargc do
if ugargv[i] == name then
return true
end
end
return false
end
location name
Definition: checkpoint_util.lua:128

◆ CheckOptionsType()

function util CheckOptionsType ( name  ,
options  ,
atype   
)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :76-83

function util.CheckOptionsType(name, options, atype)
if options ~= nil then
for i=1,#options do
ug_assert(type(options[i]) == atype, "ERROR in util.GetParam: passed option '"..options[i]..
"' for '"..name.."' not a "..atype)
end
end
end
function ug_assert(condition, msg)

References s.

◆ CheckOptionsValue()

function util CheckOptionsValue ( name  ,
value  ,
options   
)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :85-97

function util.CheckOptionsValue(name, value, options)
if options ~= nil then
local bValid = false
for i=1,#options do
if value == options[i] then bValid = true; end
end
local s = ""
local minname, imin = GetMinLevenshteinDistanceOfValue(value, options)
if imin < 5 then s = "\nDid you mean '"..minname.."' ?" end
ug_assert(bValid, "ERROR in util.GetParam: passed value '"..value.."' for '"
..name.."' not contained in options:"..util.ConcatOptions(options)..s)
end
end
parameterString s
function GetMinLevenshteinDistanceOfValue(str, list)
function table imin(t)
int local(bglp_vertex_descriptor p)
Definition: parallel_matrix.h:57

◆ ConcatOptions()

function util ConcatOptions ( options  )

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :63-74

function util.ConcatOptions(options)
local sOpt = ""
if options ~= nil then
sOpt = " ["
for i=1,#options do
if i > 1 then sOpt = sOpt.." | " end
sOpt = sOpt..options[i]
end
sOpt = sOpt.."]"
end
return sOpt
end

◆ GetCommandLine()

function util GetCommandLine ( )

returns all arguments from the command line

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :328-334

function util.GetCommandLine()
local pline = ""
for i=1, ugargc do
pline = pline..ugargv[i].." "
end
return pline
end

◆ GetMinLevenshteinDistanceOfIndex()

function GetMinLevenshteinDistanceOfIndex ( str  ,
list   
)
Returns
name, distance of the index of the table 'list' which is most equal to str

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :36-47

local namemin=""
for i,v in pairs(list) do
if d < imin then
imin = d
namemin = i
end
end
return namemin, imin
end
function GetMinLevenshteinDistanceOfIndex(str, list)
size_t LevenshteinDistance(const string &s1, const string &s2)
Definition: string_util.cpp:311

◆ GetMinLevenshteinDistanceOfValue()

function GetMinLevenshteinDistanceOfValue ( str  ,
list   
)
Returns
name, distance of the value of the table 'list' which is most equal to str

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :50-61

local namemin=""
for i,v in pairs(list) do
if d < imin then
imin = d
namemin = v
end
end
return namemin, imin
end

◆ GetParam()

function util GetParam ( name  ,
default  ,
description  ,
options  ,
atype   
)

util.GetParam returns parameter in ugargv after ugargv[i] == name

Parameters
nameparameter in ugargv to search for
defaultreturned value if 'name' is not present (default nil)
descriptiondescription for 'name' (default nil)
optionsa table of options e.g. {"jac", "sgs"}
atypetype of the parameter, e.g. "number", "string", "boolean". default "string"
Returns
parameter in ugargv after ugargv[i] == name or default if 'name' was not present

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :110-161

◆ GetParamBool()

function util GetParamBool ( name  ,
default  ,
description   
)

util.GetParamBool use with CommandLine to get boolean option, like -useAMG true

Parameters
defaultreturned value if 'name' is not present (default nil)
descriptiondescription for 'name' (default nil)
Returns
the number after the parameter 'name' or default if 'name' was not present/no number unlike util.HasParamOption , you must specify a value for your optionn, like -useAMG 1 possible values are (false): 0, n, false, (true) 1, y, j, true

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :239-251

function util.GetParamBool(name, default, description)
local r = util.GetParam(name, tostring(default), description, nil, " (bool) ")
if r == "0" or r == "false" or r == "n" then
return false
elseif r == "1" or r == "true" or r == "y" or r == "j" then
return true
else
print("ERROR in GetParamBool: passed '"..r.."' for Parameter '"..name.."' is not a bool.")
exit();
end
end

◆ GetParamFromList()

function util GetParamFromList ( name  ,
default  ,
list   
)

util.GetParamFromList use with CommandLine to get a value out of a list

Parameters
namename of the option, like -smoother
defaultreturned value if 'name' is not present (default nil)
descriptiondescription for 'name' (default nil)
Returns
the number after the parameter 'name' or default if 'name' was not present/no number unlike util.HasParamOption , you must specify a value for your optionn, like -useAMG 1 possible values are (false): 0, n, false, (true) 1, y, j, true

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :261-282

◆ GetParamNumber()

function util GetParamNumber ( name  ,
default  ,
description  ,
options   
)

util.GetParamNumber use with CommandLine to get a number, like -numRefs 4 if parameter is not specified, returns default

Parameters
nameparameter in ugargv to search for
defaultreturned value if 'name' is not present (default nil)
descriptiondescription for 'name' (default nil)
Returns
the number after the parameter 'name' or default if 'name' was not present/no number

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :171-197

◆ GetParamNumberArray()

function util GetParamNumberArray ( name  ,
default  ,
description   
)

util.GetParamNumber use with CommandLine to get an array of numbers, like -proc "1;4;9" if parameter is not specified, returns default

Parameters
nameparameter in ugargv to search for
defaultreturned value if 'name' is not present (default nil)
descriptiondescription for 'name' (default nil)
Returns
the number after the parameter 'name' or default if 'name' was not present/no number

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :206-230

◆ GetUniqueFilenameFromCommandLine()

function util GetUniqueFilenameFromCommandLine ( )

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :425-436

function util.GetUniqueFilenameFromCommandLine()
local ret=""
for i = 1, ugargc do
ret = ret.." "..ugargv[i]
end
if NumProcs() > 1 then
return ret.."_numProcs_"..NumProcs()
else
return ret
end
end
string FilenameStringEscape(string s)
Definition: misc_bridge.cpp:444
int NumProcs()
returns the number of processes
Definition: pcl_base.cpp:91

◆ GetUserParameters()

function util GetUserParameters ( params  ,
descriptors   
)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :444-460

function util.GetUserParameters(params, descriptors)
for k, v in pairs(params) do
local t = type(v)
local descriptor = descriptors and descriptors[k] or ""
if t == "boolean" then
params[k] = v or util.HasParamOption("-"..k, descriptor)
elseif t == "string" then
params[k] = util.GetParam("-"..k, v, descriptor)
elseif t == "number" then
params[k] = util.GetParamNumber("-"..k, v, descriptor)
else
print("WARNING in util.GetUserParameters: Unsupported type '"
.. t .. "' of key '" .. k .. "' in params table")
end
end
end

◆ HasParamOption()

function util HasParamOption ( name  ,
description   
)

util.HasParamOption use with CommandLine to get option, like -useAMG

Parameters
nameoption in argv to search for
descriptiondescription for 'name' (default nil)
Returns
true if option found, else false

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :290-310

◆ PrintArguments()

function util PrintArguments ( )

lists all the command line arguments which where used or could have been used with util.GetParam, util.GetParamNumber and util.HasParamOption

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :338-346

function util.PrintArguments()
local length=0
for name,arg in pairsSortedByKeys(util.args) do
length = math.max(string.len(name), length)
end
for name,arg in pairsSortedByKeys(util.args) do
print(" "..util.adjuststring(name, length, "l").." = "..arg.value)
end
end
function util adjuststring(str, len, type)
for(yylen=0;yystr[yylen];yylen++) continue

◆ PrintHelp()

function util PrintHelp ( )

prints out the description to each GetParam-parameter so far called

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :354-365

function util.PrintHelp()
local length=0
for name,arg in pairsSortedByKeys(util.args) do
length = math.max(string.len(name), length)
end
local defaultStr
for name,arg in pairsSortedByKeys(util.args) do
sOpt = util.ConcatOptions(arg.options)
print(arg.type..util.adjuststring(name, length, "l").." = "..StrOrNil(arg.value)..
" : "..arg.description..sOpt.." (default = "..StrOrNil(arg.default)..")")
end
end
function StrOrNil(s)
function util ConcatOptions(options)

◆ PrintIgnoredArguments()

function util PrintIgnoredArguments ( )

lists all command line arguments which were provided but could not be used.

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :379-422

◆ StrOrNil()

function StrOrNil ( s  )

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / command_line_util.lua :348-351

function StrOrNil(s)
if s == nil then return "nil" end
return s
end

Variable Documentation

◆ ex

◆ logtofile

parameterString logtofile = ""

Output will be written to the specified file.

◆ noquit

parameterBool noquit

Runs the interactive shell after specified script;.

◆ noterm

parameterBool noterm

Terminal logging will be disabled;.

◆ outproc

parameterNumber outproc = 0

Sets the output-proc to id.

Referenced by ug::LogIndexLayoutOnAllProcs().

◆ profile

parameterBool profile

Shows profile-output when the application terminates;.

Referenced by PrintProfile_TotalTime().