diff --git a/bin/cfg b/bin/cfg index d4ffaab..d266cfa 100755 --- a/bin/cfg +++ b/bin/cfg @@ -22,7 +22,7 @@ foreach ($autoloadFiles as $autoloadFile) { } } -$version = '0.1 beta'; +$version = '0.2'; $actions = [ 'show', 'write', 'help' ]; $settings = ['key' => '', 'value' => '']; @@ -45,6 +45,11 @@ $collection = (new Input\InputCollection()) ->description('Path to a json file to to write to') ) // }}} + ->add( Input\InputTypeFactory::build('LongOption')->name('mode')->short('m') // {{{ + ->flags(AbstractInputType::FLAG_OPTIONAL | Input\AbstractInputType::FLAG_VALUE_REQUIRED) + ->description('Set a mode') + ) // }}} + ->add( Input\InputTypeFactory::build('LongOption')->name('appPath')->short('a') // {{{ ->flags(AbstractInputType::FLAG_OPTIONAL | Input\AbstractInputType::FLAG_VALUE_REQUIRED) ->description('Path where the config/ directory for the conf files is located, defaults to the working dir') @@ -185,14 +190,20 @@ foreach(new RecursiveIteratorIterator($it) as $file) } } */ -$cfg = (new Settings())->appPath($appPath)->prefix($prefix); +$mode = ($argv->find('mode') == '') ? null : $argv->find('mode'); +$cfg = (new Settings([], $mode))->appPath($appPath)->prefix($prefix); if ($pkgPath = $argv->find('pkgPath')) $cfg->pkgPath($pkgPath); -if (is_readable($cfg->buildFileName('default'))) { - $cfg->load(); -} -elseif (is_readable($cfgFile = $cfg->buildFileName())) { - $cfg->load(require($cfgFile)); +try { + if (is_readable($cfg->buildFileName('default'))) { + $cfg->load(); + } + elseif (is_readable($cfgFile = $cfg->buildFileName())) { + $cfg->load(require($cfgFile)); + } +} catch (Exception $e) { + echo "Error: ".$e->getMessage()."\n"; + exit(1); } //var_dump($cfg); diff --git a/src/Settings.php b/src/Settings.php index be1c780..d248051 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -96,6 +96,9 @@ class Settings implements \Iterator // addModes() {{{ /** {{{ + * Adds modes to the default modes programmatically. + * Modes can and should be configured in the default configurration File + * @param Array $modes an array with the modes to add. 'index' => 'prefix' *///}}} public function addModes( array $modes ) { @@ -143,6 +146,7 @@ class Settings implements \Iterator // throw new FileNotFoundException(); } + // add modes from the drfault config file (no modes from other files are added) if (isset($this->settings['modes'])) { $this->addModes($this->settings['modes']); } @@ -152,12 +156,11 @@ class Settings implements \Iterator $localConf = false; if (file_exists($conf)) $localConf = require($conf); - if (! isset($this->mode)) - { // if a localConf Mode is set use it, or take the default conf mode + // if a mode was set in the constructor do not overwrite it + if (! isset($this->mode)) { + // if a localConf Mode is set use it, or take the default conf mode $this->mode = (isset($localConf['mode'])) ? $localConf['mode'] : $this->settings['mode']; - } - else - { + } else { $this->settings['mode'] = $this->mode; } @@ -340,7 +343,6 @@ class Settings implements \Iterator } // }}} - } /* jEdit buffer local properties {{{