blob: 6c59586ca1a42f129d4ee73f4e3eb2516ce8f4fe [file] [log] [blame]
aPieceka83b8e02023-06-07 15:25:16 +02001/**
2 * @file cmd_debug.c
3 * @author Adam Piecek <piecek@cesnet.cz>
4 * @brief 'verb' command of the libyang's yanglint tool.
5 *
6 * Copyright (c) 2023-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 NDEBUG
16
17#include "cmd.h"
18
19#include <assert.h>
20#include <getopt.h>
21#include <stdint.h>
22#include <stdio.h>
23#include <strings.h>
24
25#include "libyang.h"
26
27#include "common.h"
28#include "yl_opt.h"
29
30void
31cmd_debug_help(void)
32{
33 printf("Usage: debug (dict | xpath | dep-sets)+\n");
34}
35
36int
37cmd_debug_opt(struct yl_opt *yo, const char *cmdline, char ***posv, int *posc)
38{
39 int rc = 0, argc = 0;
40 int opt, opt_index;
41 struct option options[] = {
42 {"help", no_argument, NULL, 'h'},
43 {NULL, 0, NULL, 0}
44 };
45
46 if ((rc = parse_cmdline(cmdline, &argc, &yo->argv))) {
47 return rc;
48 }
49
50 while ((opt = getopt_long(argc, yo->argv, commands[CMD_DEBUG].optstring, options, &opt_index)) != -1) {
51 switch (opt) {
52 case 'h':
53 cmd_debug_help();
54 return 1;
55 default:
56 YLMSG_E("Unknown option.\n");
57 return 1;
58 }
59 }
60
61 *posv = &yo->argv[optind];
62 *posc = argc - optind;
63
64 return 0;
65}
66
67int
68cmd_debug_dep(struct yl_opt *yo, int posc)
69{
70 (void) yo;
71
72 if (!posc) {
73 /* no argument */
74 cmd_debug_help();
75 return 1;
76 }
77
78 return 0;
79}
80
81int
82cmd_debug_exec(struct ly_ctx **ctx, struct yl_opt *yo, const char *posv)
83{
84 (void) ctx;
85
86 assert(posv);
87
88 if (!strcasecmp("dict", posv)) {
89 yo->dbg_groups |= LY_LDGDICT;
90 } else if (!strcasecmp("xpath", posv)) {
91 yo->dbg_groups |= LY_LDGXPATH;
92 } else if (!strcasecmp("dep-sets", posv)) {
93 yo->dbg_groups |= LY_LDGDEPSETS;
94 } else {
95 YLMSG_E("Unknown debug group \"%s\"\n", posv);
96 return 1;
97 }
98
99 return 0;
100}
101
102int
103cmd_debug_fin(struct ly_ctx *ctx, struct yl_opt *yo)
104{
105 (void) ctx;
106 return ly_log_dbg_groups(yo->dbg_groups);
107}
108
109#endif