diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:20:26 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:20:26 +0000 |
commit | 044203039cebe3c05161f8f104a039d4744ca6d0 (patch) | |
tree | 1073c2308492e6aea4c66cb7436ee92db2abfd42 /tools/lint/cmd_clear.c | |
parent | Initial commit. (diff) | |
download | libyang2-044203039cebe3c05161f8f104a039d4744ca6d0.tar.xz libyang2-044203039cebe3c05161f8f104a039d4744ca6d0.zip |
Adding upstream version 2.1.30.upstream/2.1.30
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/cmd_clear.c')
-rw-r--r-- | tools/lint/cmd_clear.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/tools/lint/cmd_clear.c b/tools/lint/cmd_clear.c new file mode 100644 index 0000000..5eed6ff --- /dev/null +++ b/tools/lint/cmd_clear.c @@ -0,0 +1,99 @@ +/** + * @file cmd_clear.c + * @author Michal Vasko <mvasko@cesnet.cz> + * @author Radek Krejci <rkrejci@cesnet.cz> + * @brief 'clear' command of the libyang's yanglint tool. + * + * Copyright (c) 2015-2020 CESNET, z.s.p.o. + * + * This source code is licensed under BSD 3-Clause License (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + */ + +#define _GNU_SOURCE + +#include "cmd.h" + +#include <getopt.h> +#include <stdint.h> +#include <stdio.h> + +#include "libyang.h" + +#include "common.h" + +void +cmd_clear_help(void) +{ + printf("Usage: clear [-i] [-y]\n" + " Replace the current context with an empty one, searchpaths\n" + " are not kept.\n\n" + " -i, --make-implemented\n" + " Make the imported modules \"referenced\" from any loaded\n" + " module also implemented. If specified a second time, all the\n" + " modules are set implemented.\n" + " -y, --yang-library\n" + " Load and implement internal \"ietf-yang-library\" YANG module.\n" + " Note that this module includes definitions of mandatory state\n" + " data that can result in unexpected data validation errors.\n"); +#if 0 + " If <yang-library-data> path specified, load the modules\n" + " according to the provided yang library data.\n" +#endif +} + +void +cmd_clear(struct ly_ctx **ctx, const char *cmdline) +{ + int argc = 0; + char **argv = NULL; + int opt, opt_index; + struct option options[] = { + {"make-implemented", no_argument, NULL, 'i'}, + {"yang-library", no_argument, NULL, 'y'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + uint16_t options_ctx = LY_CTX_NO_YANGLIBRARY; + struct ly_ctx *ctx_new; + + if (parse_cmdline(cmdline, &argc, &argv)) { + goto cleanup; + } + + while ((opt = getopt_long(argc, argv, "iyh", options, &opt_index)) != -1) { + switch (opt) { + case 'i': + if (options_ctx & LY_CTX_REF_IMPLEMENTED) { + options_ctx &= ~LY_CTX_REF_IMPLEMENTED; + options_ctx |= LY_CTX_ALL_IMPLEMENTED; + } else { + options_ctx |= LY_CTX_REF_IMPLEMENTED; + } + break; + case 'y': + options_ctx &= ~LY_CTX_NO_YANGLIBRARY; + break; + case 'h': + cmd_clear_help(); + goto cleanup; + default: + YLMSG_E("Unknown option.\n"); + goto cleanup; + } + } + + if (ly_ctx_new(NULL, options_ctx, &ctx_new)) { + YLMSG_W("Failed to create context.\n"); + goto cleanup; + } + + ly_ctx_destroy(*ctx); + *ctx = ctx_new; + +cleanup: + free_cmdline(argv); +} |