Add formatting to paramcli, improve daemon set handler
This commit is contained in:
39
bin/paramcli
39
bin/paramcli
@ -53,21 +53,30 @@ function parse_options() {
|
||||
|
||||
function print_help() {
|
||||
global $argv;
|
||||
printf("Syntax:\n %s [options] {action} [args...]\n\n", basename($argv[0]));
|
||||
printf("Options:\n");
|
||||
printf(" -h,--help Show this help\n");
|
||||
printf(" -s,--server SERVER Specify the server (ip:port) to use\n");
|
||||
printf(" -f,--from DATETIME Set the validity start timestamp\n");
|
||||
printf(" -u,--until DATETIME Set the validity end timestamp\n");
|
||||
printf(" -j,--json Assume json encoded values with set\n");
|
||||
printf("\nActions:\n");
|
||||
printf(" list\n List collections\n");
|
||||
printf(" set {collection} {key}={value}*\n Set the keys to value, using the --from and --until values. Multiple\n key-value pairs can be specified. Use --json to pass values as json.\n");
|
||||
printf(" get {collection} [{when}]\n Fetch the current values, or the values at {when}.\n");
|
||||
printf(" show {collection}\n Show keys and all values, allowing to delete values.\n");
|
||||
printf(" delete {collection} {key|id}*\n Delete a key or a value from a collection\n");
|
||||
printf(" purge {collection}\n Delete an entire collection\n");
|
||||
printf(" import {collection} [filename]\n Set values from JSON read from file (or stdin)\n");
|
||||
$msg = [
|
||||
sprintf("\e[33mSyntax:\e[0m\n"),
|
||||
sprintf(" %s [options] {action} [args...]\n", basename($argv[0])),
|
||||
sprintf("\e[33mOptions:\e[0m\n"),
|
||||
sprintf(" -h,--help \e[3mShow this help\e[0m"),
|
||||
sprintf(" -s,--server SERVER \e[3mSpecify the server (ip:port) to use\e[0m"),
|
||||
sprintf(" -f,--from DATETIME \e[3mSet the validity start timestamp\e[0m"),
|
||||
sprintf(" -u,--until DATETIME \e[3mSet the validity end timestamp\e[0m"),
|
||||
sprintf(" -j,--json \e[3mAssume json encoded values with set\e[0m"),
|
||||
sprintf(""),
|
||||
sprintf("\e[33mActions:\e[0m\n"),
|
||||
sprintf(" \e[1mlist\e[0m\n\e[3m List collections\e[0m"),
|
||||
sprintf(" \e[1mset\e[0m {collection} {key}={value}*\n\e[3m Set the keys to value, using the --from and --until values. Multiple\n key-value pairs can be specified. Use --json to pass values as json.\e[0m"),
|
||||
sprintf(" \e[1mget\e[0m {collection} [{when}]\n\e[3m Fetch the current values, or the values at {when}.\e[0m"),
|
||||
sprintf(" \e[1mshow\e[0m {collection}\n\e[3m Show keys and all values, allowing to delete values.\e[0m"),
|
||||
sprintf(" \e[1mdelete\e[0m {collection} {key|id}*\n Delete a key or a value from a collection\e[0m"),
|
||||
sprintf(" \e[1mpurge\e[0m {collection}\n\e[3m Delete an entire collection\e[0m"),
|
||||
sprintf(" \e[1mimport\e[0m {collection} [filename]\n\e[3m Set values from JSON read from file (or stdin)\e[0m"),
|
||||
];
|
||||
$msg = join("\n",$msg)."\n";
|
||||
if (!posix_isatty(STDOUT)) {
|
||||
$msg = preg_replace('<\033\[(.+?)m>', '', $msg);
|
||||
}
|
||||
echo $msg;
|
||||
}
|
||||
|
||||
function exit_error(string $msg, int $code=1): never {
|
||||
|
@ -196,6 +196,9 @@ class Daemon
|
||||
|
||||
foreach ((array)$body as $change) {
|
||||
|
||||
if (!(isset($change->key) && isset($change->value))) {
|
||||
throw new \Exception("Missing key or value on update item");
|
||||
}
|
||||
// echo "Applying change (collection={$collectionName}): ".json_encode($change)."\n";
|
||||
$id = $change->id??null;
|
||||
$name = $change->key;
|
||||
|
Reference in New Issue
Block a user