/** * Parse command line into config options and commands with its parameters * * $param array $args List of arguments provided from command line */ static function parseCommandLineArgs($args) { $parsed_args = array('options' => array(), 'command' => array('name' => null, 'args' => array())); array_shift($args); $opts = GetOpt::extractLeft($args, self::$config_tpl); if ($opts === false) { Output::error('mmp: ' . reset(GetOpt::errors())); exit(1); } else { $parsed_args['options'] = $opts; } //if we didn't traverse the full array just now, move on to command parsing if (!empty($args)) { $parsed_args['command']['name'] = array_shift($args); } //consider any remaining arguments as command arguments $parsed_args['command']['args'] = $args; return $parsed_args; }