Skip to content

Commit 5e25d04

Browse files
committed
yanglint CHANGE unify options for parsing data
Unify option names in interactive and non-interactive modes for parsing data: -t is now data tree type -x is now (only in non-interactive mode) extra data tree for the RPC/Notification/action
1 parent d4e16e3 commit 5e25d04

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

tools/lint/commands.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ cmd_print_help(void)
5353
void
5454
cmd_data_help(void)
5555
{
56-
printf("data [-(-s)trict] [-x OPTION] [-d DEFAULTS] [-o <output-file>] [-f (xml | json)] [-t <additional-tree-file-name>]\n");
56+
printf("data [-(-s)trict] [-t TYPE] [-d DEFAULTS] [-o <output-file>] [-f (xml | json)] [-x <additional-tree-file-name>]\n");
5757
printf(" <data-file-name> [<JSON-rpc/action-schema-nodeid>]\n");
58-
printf("Accepted OPTIONs:\n");
58+
printf("Accepted TYPEs:\n");
5959
printf("\tauto - resolve data type (one of the following) automatically (as pyang does),\n");
6060
printf("\t this option is applicable only in case of XML input data.\n");
6161
printf("\tconfig - LYD_OPT_CONFIG\n");
@@ -70,18 +70,18 @@ cmd_data_help(void)
7070
printf("\tall-tagged - add missing default nodes and mark all the default nodes with the attribute.\n");
7171
printf("\ttrim - remove all nodes with a default value\n");
7272
printf("\timplicit-tagged - add missing nodes and mark them with the attribute\n\n");
73-
printf("Option -t:\n");
74-
printf("\tIf RPC/action/notification/RPC reply (for OPTIONs 'rpc', 'rpcreply', and 'notif') includes\n");
73+
printf("Option -x:\n");
74+
printf("\tIf RPC/action/notification/RPC reply (for TYPEs 'rpc', 'rpcreply', and 'notif') includes\n");
7575
printf("\tan XPath expression (when/must) that needs access to the configuration data, you can provide\n");
7676
printf("\tthem in a file, which will be parsed as 'config'.\n");
7777
}
7878

7979
void
8080
cmd_xpath_help(void)
8181
{
82-
printf("xpath [-x OPTION] [-t <additional-tree-file-name>] -e <XPath-expression>\n"
82+
printf("xpath [-t TYPE] [-x <additional-tree-file-name>] -e <XPath-expression>\n"
8383
" <XML-data-file-name> [<JSON-rpc/action-schema-nodeid>]\n");
84-
printf("Accepted OPTIONs:\n");
84+
printf("Accepted TYPEs:\n");
8585
printf("\tauto - resolve data type (one of the following) automatically (as pyang does),\n");
8686
printf("\t this option is applicable only in case of XML input data.\n");
8787
printf("\tconfig - LYD_OPT_CONFIG\n");
@@ -91,8 +91,8 @@ cmd_xpath_help(void)
9191
printf("\trpc - LYD_OPT_RPC\n");
9292
printf("\trpcreply - LYD_OPT_RPCREPLY (last parameter mandatory in this case)\n");
9393
printf("\tnotif - LYD_OPT_NOTIF\n\n");
94-
printf("Option -t:\n");
95-
printf("\tIf RPC/action/notification/RPC reply (for OPTIONs 'rpc', 'rpcreply', and 'notif') includes\n");
94+
printf("Option -x:\n");
95+
printf("\tIf RPC/action/notification/RPC reply (for TYPEs 'rpc', 'rpcreply', and 'notif') includes\n");
9696
printf("\tan XPath expression (when/must) that needs access to the configuration data, you can provide\n");
9797
printf("\tthem in a file, which will be parsed as 'config'.\n");
9898
}
@@ -495,10 +495,10 @@ cmd_data(const char *arg)
495495
{"defaults", required_argument, 0, 'd'},
496496
{"help", no_argument, 0, 'h'},
497497
{"format", required_argument, 0, 'f'},
498-
{"option", required_argument, 0, 'x'},
498+
{"option", required_argument, 0, 't'},
499499
{"output", required_argument, 0, 'o'},
500500
{"strict", no_argument, 0, 's'},
501-
{"validation-tree", required_argument, 0, 't'},
501+
{"validation-tree", required_argument, 0, 'x'},
502502
{NULL, 0, 0, 0}
503503
};
504504

@@ -515,7 +515,7 @@ cmd_data(const char *arg)
515515
optind = 0;
516516
while (1) {
517517
option_index = 0;
518-
c = getopt_long(argc, argv, "d:hf:o:sx:t:", long_options, &option_index);
518+
c = getopt_long(argc, argv, "d:hf:o:st:x:", long_options, &option_index);
519519
if (c == -1) {
520520
break;
521521
}
@@ -557,7 +557,7 @@ cmd_data(const char *arg)
557557
options |= LYD_OPT_STRICT;
558558
options |= LYD_OPT_OBSOLETE;
559559
break;
560-
case 'x':
560+
case 't':
561561
if (!strcmp(optarg, "auto")) {
562562
options = (options & ~LYD_OPT_TYPEMASK) | LYD_OPT_TYPEMASK;
563563
} else if (!strcmp(optarg, "config")) {
@@ -580,7 +580,7 @@ cmd_data(const char *arg)
580580
goto cleanup;
581581
}
582582
break;
583-
case 't':
583+
case 'x':
584584
val_tree = lyd_parse_path(ctx, optarg, LYD_XML, LYD_OPT_CONFIG);
585585
if (!val_tree) {
586586
fprintf(stderr, "Failed to parse the additional data tree for validation.\n");
@@ -699,7 +699,7 @@ cmd_xpath(const char *arg)
699699
case 'e':
700700
expr = optarg;
701701
break;
702-
case 'x':
702+
case 't':
703703
if (!strcmp(optarg, "auto")) {
704704
options = (options & ~LYD_OPT_TYPEMASK) | LYD_OPT_TYPEMASK;
705705
} else if (!strcmp(optarg, "config")) {
@@ -722,7 +722,7 @@ cmd_xpath(const char *arg)
722722
goto cleanup;
723723
}
724724
break;
725-
case 't':
725+
case 'x':
726726
val_tree = lyd_parse_path(ctx, optarg, LYD_XML, LYD_OPT_CONFIG);
727727
if (!val_tree) {
728728
fprintf(stderr, "Failed to parse the additional data tree for validation.\n");

tools/lint/examples/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ in the following command if you add `-f xml` option).
145145
Command and its output:
146146

147147
```
148-
> data -x config datastore.xml
148+
> data -t config datastore.xml
149149
```
150150

151-
We use option `-x` to specify type of the data in `datastore.xml`. By the
151+
We use option `-t` to specify type of the data in `datastore.xml`. By the
152152
`config` value we declare that the input file contains all the configuration
153153
data (with at least all the mandatory nodes as required by the loaded schemas),
154154
but without the status data. More examples of different data types will follow.
@@ -158,13 +158,13 @@ To handle unknown data as error, use strict mode (`-s` option).
158158
Command and its output:
159159

160160
```
161-
> data -x config -s datastore.xml
161+
> data -t config -s datastore.xml
162162
libyang[0]: Unknown element "interfaces". (path: /)
163163
Failed to parse data.
164164
```
165165

166166
Note that in case of working with complete datastore including the status data
167-
(no `-x` option is specified), `yanglint(1)` has to add status data from its
167+
(no `-t` option is specified), `yanglint(1)` has to add status data from its
168168
internal `ietf-yang-library` module. Using the `-s` option in this case forces
169169
validation in time of parsing the input file so it is expected to include also
170170
the mandatory status data from the `ietf-yang-library` module.
@@ -192,7 +192,7 @@ Command and its output:
192192
Command and its output:
193193

194194
```
195-
> data -x config -s datastore.xml
195+
> data -t config -s datastore.xml
196196
```
197197

198198
**Different data content types**
@@ -202,7 +202,7 @@ situations (e.g. as <edit-config data>, result of the <get> with status data
202202
included or as a result of the <get-config> without the status data and
203203
possibly filtered, so without specified subtrees), it must be possible to
204204
specify which kind of data is going to be parsed. In `yanglint(1)`, this is done
205-
via `-x` option. The list of supported modes can be displayed by the `-h`
205+
via `-t` option. The list of supported modes can be displayed by the `-h`
206206
option given to the `data` command. In general, the `auto` value lets the
207207
`yanglint(1)` to recognize the data type automatically by the additional top-level
208208
elements added to the parsed data. This is the same way as `pyang(1)` uses. Note,
@@ -213,7 +213,7 @@ that the automatic data type recognition is available only for the XML input.
213213
Command and its output:
214214

215215
```
216-
> data -x edit config-missing-key.xml
216+
> data -t edit config-missing-key.xml
217217
libyang[0]: Invalid (mixed names) opening (nam) and closing (name) element tags. (path: /nacm/groups/group/nam)
218218
Failed to parse data.
219219
```
@@ -223,7 +223,7 @@ Failed to parse data.
223223
Command and its output:
224224

225225
```
226-
> data -x edit config-unknown-element.xml
226+
> data -t edit config-unknown-element.xml
227227
libyang[0]: Unknown element "denied-operations". (path: /ietf-netconf-acm:nacm/denied-operations)
228228
Failed to parse data.
229229
```
@@ -469,7 +469,7 @@ Note: This example also shows `JSON` output of the command.
469469
Command and its output:
470470
```
471471
> feature -e * ietf-ip
472-
> data -f json -x config data-ip.xml
472+
> data -f json -t config data-ip.xml
473473
{
474474
"ietf-interfaces:interfaces": {
475475
"interface": [

0 commit comments

Comments
 (0)