add mode switch to cfg script

This commit is contained in:
norb 2022-11-23 08:10:40 +01:00
commit 097ca9444f
2 changed files with 26 additions and 13 deletions

21
bin/cfg
View file

@ -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'))) {
try {
if (is_readable($cfg->buildFileName('default'))) {
$cfg->load();
}
elseif (is_readable($cfgFile = $cfg->buildFileName())) {
}
elseif (is_readable($cfgFile = $cfg->buildFileName())) {
$cfg->load(require($cfgFile));
}
} catch (Exception $e) {
echo "Error: ".$e->getMessage()."\n";
exit(1);
}
//var_dump($cfg);

View file

@ -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 {{{