summaryrefslogtreecommitdiff
path: root/lib/grammar_sandbox.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-08-05 16:41:42 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-08-05 16:41:42 +0000
commit0aa2c2ff01c78e6c194c16ce1d9925af918e7e4f (patch)
tree52e9e08ef7d6419a797e6d01d5678b7ee15c9b43 /lib/grammar_sandbox.c
parent39fb395f7d628279c02c245028a6ab6029d272d7 (diff)
lib: Add docstring support
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/grammar_sandbox.c')
-rw-r--r--lib/grammar_sandbox.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c
index a2177c1767..d1779a9b6e 100644
--- a/lib/grammar_sandbox.c
+++ b/lib/grammar_sandbox.c
@@ -24,6 +24,33 @@ DEFUN (grammar_test,
return CMD_SUCCESS;
}
+DEFUN (grammar_test_doc,
+ grammar_test_doc_cmd,
+ "grammar test docstring",
+ GRAMMAR_STR
+ "Test function for docstring\n"
+ "Command end\n")
+{
+ struct cmd_element *cmd = malloc(sizeof(struct cmd_element));
+ cmd->string = "test docstring <example|selector follow> (1-255) end VARIABLE [OPTION|set lol] . VARARG";
+ cmd->doc = "Test stuff\n"
+ "docstring thing\n"
+ "first example\n"
+ "second example\n"
+ "follow\n"
+ "random range\n"
+ "end thingy\n"
+ "variable\n"
+ "optional variable\n"
+ "optional set\n"
+ "optional lol\n"
+ "vararg!\n";
+ cmd->func = NULL;
+ cmd->tokens = vector_init(VECTOR_MIN_SIZE);
+ parse_command_format(nodegraph, cmd);
+ return CMD_SUCCESS;
+}
+
DEFUN (grammar_test_show,
grammar_test_show_cmd,
"grammar tree",
@@ -52,7 +79,7 @@ DEFUN (grammar_test_complete,
else
{
fprintf(stderr, "%% Matched full input, possible completions:\n");
- char* desc = malloc(50);
+ char* desc = malloc(30);
struct listnode *node;
struct graph_node *cnode;
// print possible next hops, if any
@@ -60,7 +87,7 @@ DEFUN (grammar_test_complete,
if (cnode->type == END_GN)
fprintf(stderr, "<cr> %p\n", cnode->element->func);
else
- fprintf(stderr, "%s\n", describe_node(cnode, desc, 50));
+ fprintf(stderr, "%-30s%s\n", describe_node(cnode, desc, 30), cnode->doc);
}
free(desc);
}
@@ -118,4 +145,5 @@ void grammar_sandbox_init() {
install_element (ENABLE_NODE, &grammar_test_show_cmd);
install_element (ENABLE_NODE, &grammar_test_match_cmd);
install_element (ENABLE_NODE, &grammar_test_complete_cmd);
+ install_element (ENABLE_NODE, &grammar_test_doc_cmd);
}