blob: ad185a921db39c514dfaf94962a03b9545d56c31 [file] [log] [blame]
aPieceka83b8e02023-06-07 15:25:16 +02001/**
2 * @file yl_opt.h
3 * @author Adam Piecek <piecek@cesnet.cz>
4 * @brief Settings options for the libyang context.
5 *
6 * Copyright (c) 2020 - 2023 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef YL_OPT_H_
16#define YL_OPT_H_
17
18#include "parser_data.h" /* enum lyd_type */
19#include "printer_schema.h" /* LYS_OUTFORMAT */
20#include "set.h" /* ly_set */
21
22/**
23 * @brief Data connected with a file provided on a command line as a file path.
24 */
25struct cmdline_file {
26 struct ly_in *in;
27 const char *path;
28 LYD_FORMAT format;
29};
30
31/**
32 * @brief Create and fill the command line file data (struct cmdline_file *).
33 * @param[in] set Optional parameter in case the record is supposed to be added into a set.
34 * @param[in] in Input file handler.
35 * @param[in] path Filepath of the file.
36 * @param[in] format Format of the data file.
37 * @return The created command line file structure.
38 * @return NULL on failure
39 */
40struct cmdline_file *fill_cmdline_file(struct ly_set *set, struct ly_in *in, const char *path, LYD_FORMAT format);
41
42/**
43 * @brief Free the command line file data items.
44 * @param[in,out] rec record to free.
45 */
46void free_cmdline_file_items(struct cmdline_file *rec);
47
48/**
49 * @brief Free the command line file data (struct cmdline_file *).
50 * @param[in,out] cmdline_file The (struct cmdline_file *) to free.
51 */
52void free_cmdline_file(void *cmdline_file);
53
54/**
55 * @brief Context structure to hold and pass variables in a structured form.
56 */
57struct yl_opt {
58 /* Set to 1 if yanglint running in the interactive mode */
59 ly_bool interactive;
60 ly_bool last_one;
61
62 /* libyang context for the run */
63 char *yang_lib_file;
64 uint16_t ctx_options;
65
66 /* prepared output (--output option or stdout by default) */
67 ly_bool out_stdout;
68 struct ly_out *out;
69
70 char *searchpaths;
71 ly_bool searchdir_unset;
72
73 /* options flags */
74 uint8_t list; /* -l option to print list of schemas */
75
76 /* line length for 'tree' format */
77 size_t line_length; /* --tree-line-length */
78
79 uint32_t dbg_groups;
80
81 /*
82 * schema
83 */
84 /* set schema modules' features via --features option (struct schema_features *) */
85 struct ly_set schema_features;
86
87 /* set of loaded schema modules (struct lys_module *) */
88 struct ly_set schema_modules;
89
90 /* options to parse and print schema modules */
91 uint32_t schema_parse_options;
92 uint32_t schema_print_options;
93
94 /* specification of printing schema node subtree, option --schema-node */
95 char *schema_node_path;
96 const struct lysc_node *schema_node;
97 char *submodule;
98
99 /* name of file containing explicit context passed to callback
100 * for schema-mount extension. This also causes a callback to
101 * be registered.
102 */
103 char *schema_context_filename;
104 ly_bool extdata_unset;
105
106 /* value of --format in case of schema format */
107 LYS_OUTFORMAT schema_out_format;
108 ly_bool feature_param_format;
109 ly_bool feature_print_all;
110 char *features_output;
111
112 /*
113 * data
114 */
115 /* various options based on --type option */
116 enum lyd_type data_type;
117 uint32_t data_parse_options;
118 uint32_t data_validate_options;
119 uint32_t data_print_options;
120
121 /* flag for --merge option */
122 uint8_t data_merge;
123
124 /* value of --format in case of data format */
125 LYD_FORMAT data_out_format;
126
127 /* value of --in-format in case of data format */
128 LYD_FORMAT data_in_format;
129
130 /* input data files (struct cmdline_file *) */
131 struct ly_set data_inputs;
132
133 /* storage for --operational */
134 struct cmdline_file data_operational;
135
136 /* storage for --reply-rpc */
137 struct cmdline_file reply_rpc;
138
139 /* storage for --data-xpath */
140 struct ly_set data_xpath;
141
142 char **argv;
143};
144
145/**
146 * @brief Erase all values in @p opt.
147 *
148 * The yl_opt.interactive item is not deleted.
149 *
150 * @param[in,out] yo Option context to erase.
151 */
152void yl_opt_erase(struct yl_opt *yo);
153
154/**
155 * @brief Helper function to prepare argc, argv pair from a command line string.
156 *
157 * @param[in] cmdline Complete command line string.
158 * @param[out] argc_p Pointer to store argc value.
159 * @param[out] argv_p Pointer to store argv vector.
160 * @return 0 on success, non-zero on failure.
161 */
162int parse_cmdline(const char *cmdline, int *argc_p, char **argv_p[]);
163
164/**
165 * @brief Destructor for the argument vector prepared by ::parse_cmdline().
166 *
167 * @param[in,out] argv Argument vector to destroy.
168 */
169void free_cmdline(char *argv[]);
170
171#endif /* YL_OPT_H_ */