blob: 68ddbef2191646089a744ed81c77faba918caa42 [file] [log] [blame]
Jan Kundrátdc2b0722018-03-02 14:13:37 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
Jan Kundráta2740442018-03-22 16:56:43 +01003 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
Jan Kundrátdc2b0722018-03-02 14:13:37 +01004 *
Václav Kubernát624a8872018-03-02 17:28:47 +01005 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
Jan Kundrátdc2b0722018-03-02 14:13:37 +01006 *
7*/
8
Václav Kubernát624a8872018-03-02 17:28:47 +01009#include <boost/spirit/home/x3.hpp>
Jan Kundrátdc2b0722018-03-02 14:13:37 +010010#include <docopt.h>
Václav Kubernát624a8872018-03-02 17:28:47 +010011#include <iostream>
Jan Kundrátdc2b0722018-03-02 14:13:37 +010012#include <string>
Václav Kubernát624a8872018-03-02 17:28:47 +010013#include "CParser.hpp"
14#include "CTree.hpp"
Jan Kundrátdc2b0722018-03-02 14:13:37 +010015#include "NETCONF_CLI_VERSION.h"
16
Václav Kubernát624a8872018-03-02 17:28:47 +010017
Jan Kundrátdc2b0722018-03-02 14:13:37 +010018static const char usage[] =
Václav Kubernát624a8872018-03-02 17:28:47 +010019 R"(CLI interface to remote NETCONF hosts
Jan Kundrátdc2b0722018-03-02 14:13:37 +010020
21Usage:
Václav Kubernát624a8872018-03-02 17:28:47 +010022 netconf-cli
Jan Kundrátdc2b0722018-03-02 14:13:37 +010023 netconf-cli (-h | --help)
24 netconf-cli --version
25)";
26
Václav Kubernát624a8872018-03-02 17:28:47 +010027namespace x3 = boost::spirit::x3;
28namespace ascii = boost::spirit::x3::ascii;
29
30using Cmd = std::vector<std::string>;
31using x3::alpha;
32using x3::lit;
33using x3::char_;
34using x3::_attr;
35using x3::lexeme;
36using ascii::space;
37
Václav Kubernátff2c9f62018-05-16 20:26:31 +020038void interpret(cd_ command, CTree& tree)
Václav Kubernát624a8872018-03-02 17:28:47 +010039{
Václav Kubernátff2c9f62018-05-16 20:26:31 +020040 tree.changeNode(command.m_path);
Václav Kubernát624a8872018-03-02 17:28:47 +010041}
42
Jan Kundrátdc2b0722018-03-02 14:13:37 +010043int main(int argc, char* argv[])
44{
45 auto args = docopt::docopt(usage,
46 {argv + 1, argv + argc},
47 true,
48 "netconf-cli " NETCONF_CLI_VERSION,
49 true);
Václav Kubernát624a8872018-03-02 17:28:47 +010050 std::cout << "Welcome to netconf-cli" << std::endl;
Václav Kubernátff2c9f62018-05-16 20:26:31 +020051
52 CTree tree;
53 tree.addContainer("", "a");
54 tree.addContainer("", "b");
55 tree.addContainer("a", "a2");
56 tree.addContainer("b", "b2");
57 tree.addContainer("a/a2", "a3");
58 tree.addContainer("b/b2", "b3");
59 tree.addList("", "list", {"number"});
60 tree.addContainer("list", "contInList");
61 tree.addList("", "twoKeyList", {"number", "name"});
62 CParser parser(tree);
63
64 while (true) {
65 std::cout << tree.currentNode() << ">";
66 std::string input;
67 std::getline(std::cin, input);
68 if (std::cin.eof())
69 break;
70
71 try {
72 cd_ command = parser.parseCommand(input, std::cout);
73 interpret(command, tree);
74 } catch (InvalidCommandException& ex) {
75 std::cerr << ex.what() << std::endl;
76 }
77 }
78
Jan Kundrátdc2b0722018-03-02 14:13:37 +010079 return 0;
80}