mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-04 14:43:01 +02:00
klinfix: add CLI support for set datetime 2023-07-03T16:06:34+02:00
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
committed by
Tobias Waldekranz
parent
6dafda072a
commit
db813bd623
@@ -143,11 +143,14 @@ err:
|
||||
|
||||
int klix_rpc(kcontext_t *ctx)
|
||||
{
|
||||
kpargv_pargs_node_t *iter;
|
||||
size_t icnt = 0, ocnt = 0;
|
||||
sr_val_t *input = NULL;
|
||||
sr_session_ctx_t *sess;
|
||||
sr_conn_ctx_t *conn;
|
||||
const char *xpath;
|
||||
sr_val_t *output;
|
||||
size_t cnt;
|
||||
kparg_t *parg;
|
||||
int err;
|
||||
|
||||
xpath = kcontext_script(ctx);
|
||||
@@ -156,6 +159,21 @@ int klix_rpc(kcontext_t *ctx)
|
||||
goto err;
|
||||
}
|
||||
|
||||
iter = kpargv_pargs_iter(kcontext_pargv(ctx));
|
||||
while ((parg = kpargv_pargs_each(&iter))) {
|
||||
const char *key = kentry_name(kparg_entry(parg));
|
||||
const char *val = kparg_value(parg);
|
||||
|
||||
/* skip leading part of command line: 'set datetime' */
|
||||
if (!strcmp(key, val))
|
||||
continue;
|
||||
|
||||
sr_realloc_values(icnt, icnt + 1, &input);
|
||||
/* e.g. /ietf-system:set-current-datetime/current-datetime */
|
||||
sr_val_build_xpath(&input[icnt], "%s/%s", xpath, key);
|
||||
sr_val_set_str_data(&input[icnt++], SR_STRING_T, val);
|
||||
}
|
||||
|
||||
if (sr_connect(SR_CONN_DEFAULT, &conn)) {
|
||||
fprintf(stderr, "Error: Connection to datastore failed\n");
|
||||
goto err;
|
||||
@@ -166,23 +184,25 @@ int klix_rpc(kcontext_t *ctx)
|
||||
goto err_disconnect;
|
||||
}
|
||||
|
||||
if ((err = sr_rpc_send(sess, xpath, NULL, 0, 0, &output, &cnt))) {
|
||||
if ((err = sr_rpc_send(sess, xpath, input, icnt, 0, &output, &ocnt))) {
|
||||
fprintf(stderr, "Failed sending RPC %s: %s", xpath, sr_strerror(err));
|
||||
goto err_disconnect;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
for (size_t i = 0; i < ocnt; i++) {
|
||||
sr_print_val(&output[i]);
|
||||
puts("");
|
||||
}
|
||||
|
||||
sr_free_values(output, cnt);
|
||||
sr_free_values(input, icnt);
|
||||
sr_free_values(output, ocnt);
|
||||
sr_disconnect(conn);
|
||||
return 0;
|
||||
|
||||
err_disconnect:
|
||||
sr_disconnect(conn);
|
||||
err:
|
||||
sr_free_values(input, icnt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
<ACTION sym="STRING"/>
|
||||
</PTYPE>
|
||||
|
||||
<PTYPE name="GETSTR">
|
||||
<ACTION sym="STRING"/>
|
||||
</PTYPE>
|
||||
|
||||
<PTYPE name="PLINE_SET">
|
||||
<COMPL>
|
||||
<ACTION sym="srp_compl@sysrepo"/>
|
||||
@@ -121,7 +125,17 @@
|
||||
<ACTION sym="klix_copy@klinfix"/>
|
||||
</COMMAND>
|
||||
|
||||
<COMMAND name="set" help="Set" mode="switch">
|
||||
<COMMAND name="datetime" help="Set current date and time">
|
||||
<PARAM name="current-datetime" ptype="/GETSTR" help="yyyy-mm-ddThh:mm:ss(Z|+/-hh:mm)"/>
|
||||
<ACTION sym="klix_rpc@klinfix">/ietf-system:set-current-datetime</ACTION>
|
||||
</COMMAND>
|
||||
</COMMAND>
|
||||
|
||||
<COMMAND name="show" help="Show" mode="switch">
|
||||
<COMMAND name="datetime" help="Show current date and time">
|
||||
<ACTION sym="script">date -Isec</ACTION>
|
||||
</COMMAND>
|
||||
<COMMAND name="running-config" help="Show running-config">
|
||||
<ACTION sym="srp_show_running@sysrepo"/>
|
||||
</COMMAND>
|
||||
|
||||
Reference in New Issue
Block a user