從zebra裏提取的命令行實現。
- 示例:
// 定義:
DEFUN (cmd_show_something, cmd_show_something_s,
"show something",
"Show something\n") {
fprintf(stdout, "I whill show something...");
return CMD_SUCCESS;
}
// 註冊:
install_element(VIEW_NODE, &cmd_show_something_s);
// 主函數:
void clitest_main(int argc, char *argv[]) {
vtysh_main(argc, argv, NULL);
}
效果如下:
$ ./clitest
someApp (version V1.0).
Copyright 2018-2019 XXX.
ubuntu>
exit Exit current mode and down to previous mode
list Print command list
quit Exit current mode and down to previous mode
show Show something
ubuntu> show something
I whill show something...
ubuntu> ex
$