Adding support for props being set with env. variables, e.g: TASKMAN_SET_foo=1 => foo=1
Publish PHP Package / docker (push) Successful in 6s Details

This commit is contained in:
Pavel Shevaev 2024-07-23 14:21:50 +03:00
parent 2cbde0efb4
commit f2c9251e52
1 changed files with 25 additions and 4 deletions

View File

@ -496,6 +496,21 @@ function _parse_taskstr($str)
return $task_spec; return $task_spec;
} }
function _read_env_vars()
{
$envs = getenv(null);
foreach($envs as $k => $v)
{
if(strpos($k, 'TASKMAN_SET_') === 0)
{
$prop_name = substr($k, 12);
msg_sys("Setting prop '$prop_name' (with env '$k')\n");
set($prop_name, $v);
}
}
}
function _process_argv(&$argv) function _process_argv(&$argv)
{ {
global $TASKMAN_LOG_LEVEL; global $TASKMAN_LOG_LEVEL;
@ -549,9 +564,10 @@ function _process_argv(&$argv)
$def_name = substr($v, 0, $eq_pos); $def_name = substr($v, 0, $eq_pos);
$def_value = substr($v, $eq_pos+1); $def_value = substr($v, $eq_pos+1);
if(in_array(strtolower($def_value), array('yes', 'true'), true/*strict*/)) //TODO: this code must be more robust
if(strtolower($def_value) === 'true')
$def_value = true; $def_value = true;
else if(in_array(strtolower($def_value), array('no', 'false'), true/*strict*/)) else if(strtolower($def_value) === 'false')
$def_value = false; $def_value = false;
} }
else else
@ -560,7 +576,7 @@ function _process_argv(&$argv)
$def_value = 1; $def_value = 1;
} }
msg_sys("Setting prop $def_name=" . (is_bool($def_value) ? ($def_value ? 'true' : 'false') : $def_value) . "\n"); msg_sys("Setting prop '$def_name'=" . var_export($def_value, true) . "\n");
set($def_name, $def_value); set($def_name, $def_value);
$process_defs = false; $process_defs = false;
@ -572,14 +588,19 @@ function _process_argv(&$argv)
} }
function main($argv = array(), $help_func = null, $proc_argv = true) function main($argv = array(), $help_func = null, $proc_argv = true, $read_env_vars = true)
{ {
$GLOBALS['TASKMAN_START_TIME'] = microtime(true); $GLOBALS['TASKMAN_START_TIME'] = microtime(true);
if($help_func) if($help_func)
$GLOBALS['TASKMAN_HELP_FUNC'] = $help_func; $GLOBALS['TASKMAN_HELP_FUNC'] = $help_func;
if($read_env_vars)
_read_env_vars();
if($proc_argv) if($proc_argv)
_process_argv($argv); _process_argv($argv);
$GLOBALS['TASKMAN_SCRIPT'] = array_shift($argv); $GLOBALS['TASKMAN_SCRIPT'] = array_shift($argv);
_collect_tasks(); _collect_tasks();