|
10 | 10 | import textwrap |
11 | 11 |
|
12 | 12 | sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix()) |
13 | | -from lib import YnlFamily, Netlink, NlError |
| 13 | +from lib import YnlFamily, Netlink, NlError, SpecFamily |
14 | 14 |
|
15 | 15 | sys_schema_dir='/usr/share/ynl' |
16 | 16 | relative_schema_dir='../../../../Documentation/netlink' |
@@ -127,6 +127,7 @@ def main(): |
127 | 127 | group.add_argument('--list-msgs', action='store_true') |
128 | 128 | group.add_argument('--list-attrs', dest='list_attrs', metavar='OPERATION', type=str, |
129 | 129 | help='List attributes for an operation') |
| 130 | + group.add_argument('--validate', action='store_true') |
130 | 131 |
|
131 | 132 | parser.add_argument('--duration', dest='duration', type=int, |
132 | 133 | help='when subscribed, watch for DURATION seconds') |
@@ -168,15 +169,25 @@ def output(msg): |
168 | 169 |
|
169 | 170 | if args.family: |
170 | 171 | spec = f"{spec_dir()}/{args.family}.yaml" |
171 | | - if args.schema is None and spec.startswith(sys_schema_dir): |
172 | | - args.schema = '' # disable schema validation when installed |
173 | | - if args.process_unknown is None: |
174 | | - args.process_unknown = True |
175 | 172 | else: |
176 | 173 | spec = args.spec |
177 | 174 | if not os.path.isfile(spec): |
178 | 175 | raise Exception(f"Spec file {spec} does not exist") |
179 | 176 |
|
| 177 | + if args.validate: |
| 178 | + try: |
| 179 | + SpecFamily(spec, args.schema) |
| 180 | + except Exception as error: |
| 181 | + print(error) |
| 182 | + exit(1) |
| 183 | + return |
| 184 | + |
| 185 | + if args.family: # set behaviour when using installed specs |
| 186 | + if args.schema is None and spec.startswith(sys_schema_dir): |
| 187 | + args.schema = '' # disable schema validation when installed |
| 188 | + if args.process_unknown is None: |
| 189 | + args.process_unknown = True |
| 190 | + |
180 | 191 | ynl = YnlFamily(spec, args.schema, args.process_unknown, |
181 | 192 | recv_size=args.dbg_small_recv) |
182 | 193 | if args.dbg_small_recv: |
|
0 commit comments