From e31f4dbec66d2ca74fb11e3d5e6506e7a33b508e Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 29 Mar 2018 13:01:06 -0400 Subject: [PATCH] lib, python: DEFPY_ATTR, DEFPY_HIDDEN Add support for element attributes in DEFPY macros. Signed-off-by: Quentin Young --- lib/command.h | 10 ++++++++++ lib/defun_lex.l | 2 ++ python/clidef.py | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/command.h b/lib/command.h index 8d88ea1902..508b905381 100644 --- a/lib/command.h +++ b/lib/command.h @@ -221,6 +221,13 @@ struct cmd_node { DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \ funcdecl_##funcname +#define DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \ + DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0) \ + funcdecl_##funcname + +#define DEFPY_HIDDEN(funcname, cmdname, cmdstr, helpstr) \ + DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN) + #define DEFUN(funcname, cmdname, cmdstr, helpstr) \ DEFUN_CMD_FUNC_DECL(funcname) \ DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \ @@ -298,6 +305,9 @@ struct cmd_node { #else /* VTYSH_EXTRACT_PL */ #define DEFPY(funcname, cmdname, cmdstr, helpstr) \ DEFUN(funcname, cmdname, cmdstr, helpstr) + +#define DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \ + DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, attr) #endif /* VTYSH_EXTRACT_PL */ /* Some macroes */ diff --git a/lib/defun_lex.l b/lib/defun_lex.l index 87775a0e75..9c995db266 100644 --- a/lib/defun_lex.l +++ b/lib/defun_lex.l @@ -132,6 +132,8 @@ SPECIAL [(),] "DEFUN_NOSH" value = strdup(yytext); return DEFUNNY; "DEFUN_HIDDEN" value = strdup(yytext); return DEFUNNY; "DEFPY" value = strdup(yytext); return DEFUNNY; +"DEFPY_ATTR" value = strdup(yytext); return DEFUNNY; +"DEFPY_HIDDEN" value = strdup(yytext); return DEFUNNY; "ALIAS" value = strdup(yytext); return DEFUNNY; "ALIAS_HIDDEN" value = strdup(yytext); return DEFUNNY; "install_element" value = strdup(yytext); return INSTALL; diff --git a/python/clidef.py b/python/clidef.py index fe01a89162..2e55909647 100644 --- a/python/clidef.py +++ b/python/clidef.py @@ -186,7 +186,7 @@ def process_file(fn, ofd, dumpfd, all_defun): filedata = clippy.parse(fn) for entry in filedata['data']: - if entry['type'] == 'DEFPY' or (all_defun and entry['type'].startswith('DEFUN')): + if entry['type'].startswith('DEFPY') or (all_defun and entry['type'].startswith('DEFUN')): cmddef = entry['args'][2] cmddef = ''.join([i[1:-1] for i in cmddef]) -- 2.39.5