blob: 344900d410cf8e718cf86664721b0790270144a1 [file] [log] [blame]
Radek Krejcie9f13b12020-11-09 17:42:04 +01001/**
2 * @file cmd.c
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @author Radek Krejci <rkrejci@cesnet.cz>
aPieceka83b8e02023-06-07 15:25:16 +02005 * @author Adam Piecek <piecek@cesnet.cz>
Radek Krejcie9f13b12020-11-09 17:42:04 +01006 * @brief libyang's yanglint tool general commands
7 *
aPieceka83b8e02023-06-07 15:25:16 +02008 * Copyright (c) 2015-2023 CESNET, z.s.p.o.
Radek Krejcie9f13b12020-11-09 17:42:04 +01009 *
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
31COMMAND commands[];
32extern int done;
33
Radek Krejcie9f13b12020-11-09 17:42:04 +010034void
aPiecek647f62e2023-05-18 10:55:58 +020035cmd_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
aPieceka83b8e02023-06-07 15:25:16 +020046int
47cmd_quit_exec(struct ly_ctx **UNUSED(ctx), struct yl_opt *UNUSED(yo), const char *UNUSED(posv))
Radek Krejcie9f13b12020-11-09 17:42:04 +010048{
49 done = 1;
aPieceka83b8e02023-06-07 15:25:16 +020050 return 0;
Radek Krejcie9f13b12020-11-09 17:42:04 +010051}
52
aPiecek15cc4cf2023-04-17 15:23:21 +020053/* Also keep enum COMMAND_INDEX updated. */
Radek Krejcie9f13b12020-11-09 17:42:04 +010054COMMAND commands[] = {
aPieceka83b8e02023-06-07 15:25:16 +020055 {
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 {
aPiecekcf9e7682023-06-19 14:03:50 +020072 "data", cmd_data_opt, cmd_data_dep, cmd_data_store, cmd_data_process, cmd_data_help, NULL,
aPieceka83b8e02023-06-07 15:25:16 +020073 "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 {
aPiecek6fde6d02023-06-21 15:06:45 +020080 "feature", cmd_feature_opt, cmd_feature_dep, cmd_feature_exec, cmd_feature_fin, cmd_feature_help, NULL,
aPieceka83b8e02023-06-07 15:25:16 +020081 "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 Krejcie9f13b12020-11-09 17:42:04 +010099#ifndef NDEBUG
aPieceka83b8e02023-06-07 15:25:16 +0200100 {
aPiecekcf9e7682023-06-19 14:03:50 +0200101 "debug", cmd_debug_opt, cmd_debug_dep, cmd_debug_store, cmd_debug_setlog, cmd_debug_help, NULL,
aPieceka83b8e02023-06-07 15:25:16 +0200102 "Display specific debug message groups", "h"
103 },
Radek Krejcie9f13b12020-11-09 17:42:04 +0100104#endif
aPieceka83b8e02023-06-07 15:25:16 +0200105 {"quit", NULL, NULL, cmd_quit_exec, NULL, NULL, NULL, "Quit the program", "h"},
Radek Krejcie9f13b12020-11-09 17:42:04 +0100106 /* synonyms for previous commands */
aPieceka83b8e02023-06-07 15:25:16 +0200107 {"?", 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 Krejcie9f13b12020-11-09 17:42:04 +0100110};