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