diff --git a/taskman.inc.php b/taskman.inc.php index 4dbf599..7356ed4 100644 --- a/taskman.inc.php +++ b/taskman.inc.php @@ -496,6 +496,21 @@ function _parse_taskstr($str) 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) { global $TASKMAN_LOG_LEVEL; @@ -549,9 +564,10 @@ function _process_argv(&$argv) $def_name = substr($v, 0, $eq_pos); $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; - else if(in_array(strtolower($def_value), array('no', 'false'), true/*strict*/)) + else if(strtolower($def_value) === 'false') $def_value = false; } else @@ -560,7 +576,7 @@ function _process_argv(&$argv) $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); $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); if($help_func) $GLOBALS['TASKMAN_HELP_FUNC'] = $help_func; + + if($read_env_vars) + _read_env_vars(); + if($proc_argv) _process_argv($argv); + $GLOBALS['TASKMAN_SCRIPT'] = array_shift($argv); _collect_tasks();