Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file cmd.c |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @author Radek Krejci <rkrejci@cesnet.cz> |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 5 | * @author Adam Piecek <piecek@cesnet.cz> |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 6 | * @brief libyang's yanglint tool general commands |
| 7 | * |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 8 | * Copyright (c) 2015-2023 CESNET, z.s.p.o. |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 9 | * |
| 10 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 11 | * You may not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * https://opensource.org/licenses/BSD-3-Clause |
| 15 | */ |
| 16 | |
| 17 | #define _GNU_SOURCE |
| 18 | |
| 19 | #include "cmd.h" |
| 20 | |
| 21 | #include <getopt.h> |
| 22 | #include <stdint.h> |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
| 25 | #include <strings.h> |
| 26 | |
| 27 | #include "common.h" |
| 28 | #include "compat.h" |
| 29 | #include "libyang.h" |
| 30 | |
| 31 | COMMAND commands[]; |
| 32 | extern int done; |
| 33 | |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 34 | void |
aPiecek | 647f62e | 2023-05-18 10:55:58 +0200 | [diff] [blame] | 35 | cmd_free(void) |
| 36 | { |
| 37 | uint16_t i; |
| 38 | |
| 39 | for (i = 0; commands[i].name; i++) { |
| 40 | if (commands[i].free_func) { |
| 41 | commands[i].free_func(); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 46 | int |
| 47 | cmd_quit_exec(struct ly_ctx **UNUSED(ctx), struct yl_opt *UNUSED(yo), const char *UNUSED(posv)) |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 48 | { |
| 49 | done = 1; |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 50 | return 0; |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 51 | } |
| 52 | |
aPiecek | 15cc4cf | 2023-04-17 15:23:21 +0200 | [diff] [blame] | 53 | /* Also keep enum COMMAND_INDEX updated. */ |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 54 | COMMAND commands[] = { |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 55 | { |
| 56 | "help", cmd_help_opt, NULL, cmd_help_exec, NULL, cmd_help_help, NULL, |
| 57 | "Display commands description", "h" |
| 58 | }, |
| 59 | { |
| 60 | "add", cmd_add_opt, cmd_add_dep, cmd_add_exec, NULL, cmd_add_help, NULL, |
| 61 | "Add a new module from a specific file", "DF:hiX" |
| 62 | }, |
| 63 | { |
| 64 | "load", cmd_load_opt, cmd_load_dep, cmd_load_exec, NULL, cmd_load_help, NULL, |
| 65 | "Load a new schema from the searchdirs", "F:hiX" |
| 66 | }, |
| 67 | { |
| 68 | "print", cmd_print_opt, cmd_print_dep, cmd_print_exec, NULL, cmd_print_help, NULL, |
| 69 | "Print a module", "f:hL:o:P:q" |
| 70 | }, |
| 71 | { |
aPiecek | cf9e768 | 2023-06-19 14:03:50 +0200 | [diff] [blame] | 72 | "data", cmd_data_opt, cmd_data_dep, cmd_data_store, cmd_data_process, cmd_data_help, NULL, |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 73 | "Load, validate and optionally print instance data", "d:ef:F:hmo:O:R:r:nt:x:" |
| 74 | }, |
| 75 | { |
| 76 | "list", cmd_list_opt, cmd_list_dep, cmd_list_exec, NULL, cmd_list_help, NULL, |
| 77 | "List all the loaded modules", "f:h" |
| 78 | }, |
| 79 | { |
aPiecek | 6fde6d0 | 2023-06-21 15:06:45 +0200 | [diff] [blame^] | 80 | "feature", cmd_feature_opt, cmd_feature_dep, cmd_feature_exec, cmd_feature_fin, cmd_feature_help, NULL, |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 81 | "Print all features of module(s) with their state", "haf" |
| 82 | }, |
| 83 | { |
| 84 | "searchpath", cmd_searchpath_opt, NULL, cmd_searchpath_exec, NULL, cmd_searchpath_help, NULL, |
| 85 | "Print/set the search path(s) for schemas", "ch" |
| 86 | }, |
| 87 | { |
| 88 | "extdata", cmd_extdata_opt, cmd_extdata_dep, cmd_extdata_exec, NULL, cmd_extdata_help, cmd_extdata_free, |
| 89 | "Set the specific data required by an extension", "ch" |
| 90 | }, |
| 91 | { |
| 92 | "clear", cmd_clear_opt, cmd_clear_dep, cmd_clear_exec, NULL, cmd_clear_help, NULL, |
| 93 | "Clear the context - remove all the loaded modules", "iyhY:" |
| 94 | }, |
| 95 | { |
| 96 | "verb", cmd_verb_opt, cmd_verb_dep, cmd_verb_exec, NULL, cmd_verb_help, NULL, |
| 97 | "Change verbosity", "h" |
| 98 | }, |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 99 | #ifndef NDEBUG |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 100 | { |
aPiecek | cf9e768 | 2023-06-19 14:03:50 +0200 | [diff] [blame] | 101 | "debug", cmd_debug_opt, cmd_debug_dep, cmd_debug_store, cmd_debug_setlog, cmd_debug_help, NULL, |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 102 | "Display specific debug message groups", "h" |
| 103 | }, |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 104 | #endif |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 105 | {"quit", NULL, NULL, cmd_quit_exec, NULL, NULL, NULL, "Quit the program", "h"}, |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 106 | /* synonyms for previous commands */ |
aPiecek | a83b8e0 | 2023-06-07 15:25:16 +0200 | [diff] [blame] | 107 | {"?", NULL, NULL, cmd_help_exec, NULL, NULL, NULL, "Display commands description", "h"}, |
| 108 | {"exit", NULL, NULL, cmd_quit_exec, NULL, NULL, NULL, "Quit the program", "h"}, |
| 109 | {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} |
Radek Krejci | e9f13b1 | 2020-11-09 17:42:04 +0100 | [diff] [blame] | 110 | }; |