Skip to content

Commit

Permalink
Adding CLI support for configuration
Browse files Browse the repository at this point in the history
Added
--config "item" "value"
--config "item"         (set to default)
--dumpconfig

options to CLI interface

Could come in handy when locking yourself out of the web
interface or, bulk changes or scripted deployment.

Issue #28
  • Loading branch information
jeroenrnl committed Oct 28, 2012
1 parent 0e28ffb commit 06b0fd4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
22 changes: 21 additions & 1 deletion php/cli/arguments.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function process() {
$args["pplace"]=array();

/*
Used short arguments: A D H I N P V a c d f h i l n p r t u v w
Used short arguments: A C D H I N P V a c d f h i l n p r t u v w
*/

for($i=0; $i<sizeof($argv); $i++) {
Expand Down Expand Up @@ -126,6 +126,20 @@ private function process() {
}
$parent=0;
break;

case "--config":
case "-C":
self::$command="config";
$args["_configitem"]=$argv[++$i];
if(isset($argv[$i+1])) {
$args["_configvalue"]=$argv[++$i];
} else {
$args["_configdefault"]=true;
}
break;
case "--dumpconfig":
self::$command="dumpconfig";
break;
case "--fields":
case "--field":
case "-f":
Expand Down Expand Up @@ -480,6 +494,12 @@ private function lookup() {
$vars[$field]=$value;
}
break;
case "_configitem":
case "_configvalue":
case "_configdefault":
$vars[$type]=$arg;
break;

}
}
}
Expand Down
36 changes: 36 additions & 0 deletions php/cli/cli.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,42 @@ public function run() {
case "new":
$this->addNew();
break;
case "config":
$vars=$this->args->getVars();
$name=$vars["_configitem"];
$default=isset($vars["_configdefault"]);
$item=conf::getItemByName($name);

if($default) {
$value=$item->getDefault();
} else {
$value=$vars["_configvalue"];
}

if(settings::$importVerbose > 0) {
echo "Setting config \"$name\" to \"$value\"" . ( $default ? " (default)" : "" ) . "\n";
}


$item->setValue($value);
$item->update();


break;
case "dumpconfig":
$conf=conf::getAll();
foreach ($conf as $name=>$item) {
foreach ($item as $citem) {
if($citem instanceof confItemBool) {
$value=( $citem->getValue() ? "true": "false" );
} else {
$value=$citem->getValue();
}
echo $citem->getName() . ": " . $value . "\n";
}
}
break;

default:
echo "Unknown command, please file a bug\n";
exit(self::EXIT_UNKNOWN_ERROR);
Expand Down

0 comments on commit 06b0fd4

Please sign in to comment.