blob: 5bf4600a2e8d8f892eeefcf8056fe260c2863a5d [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
9#include <docopt.h>
Václav Kubernát624a8872018-03-02 17:28:47 +010010#include <iostream>
Jan Kundrátdc2b0722018-03-02 14:13:37 +010011#include "NETCONF_CLI_VERSION.h"
Václav Kubernát96344a12018-05-28 16:33:39 +020012#include "interpreter.hpp"
Václav Kubernátbddbb172018-06-13 16:27:39 +020013#include "static_schema.hpp"
Jan Kundrátdc2b0722018-03-02 14:13:37 +010014
Václav Kubernát624a8872018-03-02 17:28:47 +010015
Jan Kundrátdc2b0722018-03-02 14:13:37 +010016static const char usage[] =
Václav Kubernát624a8872018-03-02 17:28:47 +010017 R"(CLI interface to remote NETCONF hosts
Jan Kundrátdc2b0722018-03-02 14:13:37 +010018
19Usage:
Václav Kubernát624a8872018-03-02 17:28:47 +010020 netconf-cli
Jan Kundrátdc2b0722018-03-02 14:13:37 +010021 netconf-cli (-h | --help)
22 netconf-cli --version
23)";
24
Václav Kubernát624a8872018-03-02 17:28:47 +010025
Jan Kundrátdc2b0722018-03-02 14:13:37 +010026int main(int argc, char* argv[])
27{
28 auto args = docopt::docopt(usage,
29 {argv + 1, argv + argc},
30 true,
31 "netconf-cli " NETCONF_CLI_VERSION,
32 true);
Václav Kubernát624a8872018-03-02 17:28:47 +010033 std::cout << "Welcome to netconf-cli" << std::endl;
Václav Kubernátff2c9f62018-05-16 20:26:31 +020034
Václav Kubernát744f57f2018-06-29 22:46:26 +020035 auto yangschema = std::make_shared<StaticSchema>();
36 yangschema->addModule("mod");
37 yangschema->addContainer("", "mod:a", yang::ContainerTraits::Presence);
38 yangschema->addContainer("", "mod:b");
39 yangschema->addContainer("mod:a", "mod:a2", yang::ContainerTraits::Presence);
40 yangschema->addContainer("mod:b", "mod:b2");
41 yangschema->addContainer("mod:a/mod:a2", "mod:a3");
42 yangschema->addContainer("mod:b/mod:b2", "mod:b3");
43 yangschema->addList("", "mod:list", {"number"});
44 yangschema->addContainer("mod:list", "contInList");
45 yangschema->addList("", "mod:twoKeyList", {"number", "name"});
46 Parser parser(yangschema);
Václav Kubernátff2c9f62018-05-16 20:26:31 +020047
48 while (true) {
Václav Kubernátf2e463f2018-05-28 15:51:08 +020049 std::cout << parser.currentNode() << "> ";
Václav Kubernátff2c9f62018-05-16 20:26:31 +020050 std::string input;
51 std::getline(std::cin, input);
52 if (std::cin.eof())
53 break;
54
55 try {
Václav Kubernátb61336d2018-05-28 17:35:03 +020056 command_ cmd = parser.parseCommand(input, std::cout);
Václav Kubernát744f57f2018-06-29 22:46:26 +020057 boost::apply_visitor(Interpreter(parser, *yangschema), cmd);
Václav Kubernátff2c9f62018-05-16 20:26:31 +020058 } catch (InvalidCommandException& ex) {
59 std::cerr << ex.what() << std::endl;
60 }
61 }
62
Jan Kundrátdc2b0722018-03-02 14:13:37 +010063 return 0;
64}