diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 4b9fd689..6c079f84 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -38,6 +38,8 @@ All notable changes to the project are documented in this file. exposing the set of PMD types currently supported. Useful for SFP/SFP+ diagnosis: an LR-only optic narrows the list to a single entry, confirming the transceiver without `ethtool -m` +- New CLI command `show operational`, and XPath filtering for this and any of + the other datastores, using `[path /path/to/subtree]` ### Fixes diff --git a/src/bin/copy.c b/src/bin/copy.c index 80334450..bd6a5972 100644 --- a/src/bin/copy.c +++ b/src/bin/copy.c @@ -283,6 +283,7 @@ static void rmtmp(const char *path) static void sysrepo_print_error(sr_session_ctx_t *sess) { const sr_error_info_t *erri = NULL; + const char *msg; int err; if (!sess) @@ -292,7 +293,10 @@ static void sysrepo_print_error(sr_session_ctx_t *sess) if (err || !erri || !erri->err_count) return; - warnx("%s (%d)", erri->err->message, erri->err->err_code); + msg = erri->err->message; + if (!msg) + msg = sr_strerror(erri->err->err_code); + warnx("%s (%d)", msg, erri->err->err_code); } /* Connect to sysrepo and create NACM-aware session on running datastore */ diff --git a/src/bin/show/__init__.py b/src/bin/show/__init__.py index 68b2ef41..14785d9c 100755 --- a/src/bin/show/__init__.py +++ b/src/bin/show/__init__.py @@ -17,17 +17,18 @@ def get_json(xpath: str, datastore: str = "operational", quiet: bool = False) -> print("Invalid XPATH. It must be a valid string starting with '/'.") return {} - try: - result = subprocess.run(["copy", datastore, "-x", shlex.quote(xpath)], - capture_output=True, text=True, check=True) - if not result.stdout.strip(): - return {} - json_data = json.loads(result.stdout) - return json_data - except subprocess.CalledProcessError as e: - if not quiet: - print(f"Error running copy: {e}") + result = subprocess.run(["copy", datastore, "-x", shlex.quote(xpath)], + capture_output=True, text=True) + if result.returncode != 0: + # copy already wrote a 'failed retrieving …' message (and a + # sysrepo error line) to stderr; relay it verbatim. + if not quiet and result.stderr: + print(result.stderr.rstrip()) return {} + if not result.stdout.strip(): + return {} + try: + return json.loads(result.stdout) except json.JSONDecodeError as e: if not quiet: print(f"Error parsing JSON output: {e}") diff --git a/src/klish-plugin-infix/xml/infix.xml b/src/klish-plugin-infix/xml/infix.xml index 250cd837..bfb3b9b3 100644 --- a/src/klish-plugin-infix/xml/infix.xml +++ b/src/klish-plugin-infix/xml/infix.xml @@ -737,15 +737,39 @@ echo "Public: $pub" - copy factory | jq -C . |pager + + + + + + copy factory ${KLISH_PARAM_xpath:+-x $KLISH_PARAM_xpath} | jq -C . |pager - copy running | jq -C . |pager + + + + + + copy running ${KLISH_PARAM_xpath:+-x $KLISH_PARAM_xpath} | jq -C . |pager - copy startup | jq -C . |pager + + + + + + copy startup ${KLISH_PARAM_xpath:+-x $KLISH_PARAM_xpath} | jq -C . |pager + + + + + + + + + copy operational ${KLISH_PARAM_xpath:+-x $KLISH_PARAM_xpath} | jq -C . |pager