blob: 2358dff5fe5df102106ca25e64052b64428e0727 [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át2b684612018-08-09 18:55:24 +020010#include <experimental/filesystem>
Václav Kubernát624a8872018-03-02 17:28:47 +010011#include <iostream>
Jan Kundrátdc2b0722018-03-02 14:13:37 +010012#include "NETCONF_CLI_VERSION.h"
Václav Kubernát96344a12018-05-28 16:33:39 +020013#include "interpreter.hpp"
Václav Kubernát2b684612018-08-09 18:55:24 +020014#include "yang_schema.hpp"
Jan Kundrátdc2b0722018-03-02 14:13:37 +010015
Václav Kubernát624a8872018-03-02 17:28:47 +010016
Jan Kundrátdc2b0722018-03-02 14:13:37 +010017static const char usage[] =
Václav Kubernát624a8872018-03-02 17:28:47 +010018 R"(CLI interface to remote NETCONF hosts
Jan Kundrátdc2b0722018-03-02 14:13:37 +010019
20Usage:
Václav Kubernát2b684612018-08-09 18:55:24 +020021 netconf-cli <path-to-yang-schema>...
Jan Kundrátdc2b0722018-03-02 14:13:37 +010022 netconf-cli (-h | --help)
23 netconf-cli --version
24)";
25
Václav Kubernát624a8872018-03-02 17:28:47 +010026
Jan Kundrátdc2b0722018-03-02 14:13:37 +010027int main(int argc, char* argv[])
28{
29 auto args = docopt::docopt(usage,
30 {argv + 1, argv + argc},
31 true,
32 "netconf-cli " NETCONF_CLI_VERSION,
33 true);
Václav Kubernát624a8872018-03-02 17:28:47 +010034 std::cout << "Welcome to netconf-cli" << std::endl;
Václav Kubernátff2c9f62018-05-16 20:26:31 +020035
Václav Kubernát2b684612018-08-09 18:55:24 +020036 auto yangschema = std::make_shared<YangSchema>();
Václav Kubernát744f57f2018-06-29 22:46:26 +020037 Parser parser(yangschema);
Václav Kubernátff2c9f62018-05-16 20:26:31 +020038
Václav Kubernát2b684612018-08-09 18:55:24 +020039 for (auto it : args.at("<path-to-yang-schema>").asStringList()) {
40 auto dir = std::experimental::filesystem::absolute(it).remove_filename();
41 yangschema->addSchemaDirectory(dir.c_str());
42 yangschema->addSchemaFile(it.c_str());
43 }
44
Václav Kubernátff2c9f62018-05-16 20:26:31 +020045 while (true) {
Václav Kubernátf2e463f2018-05-28 15:51:08 +020046 std::cout << parser.currentNode() << "> ";
Václav Kubernátff2c9f62018-05-16 20:26:31 +020047 std::string input;
48 std::getline(std::cin, input);
49 if (std::cin.eof())
50 break;
51
52 try {
Václav Kubernátb61336d2018-05-28 17:35:03 +020053 command_ cmd = parser.parseCommand(input, std::cout);
Václav Kubernát744f57f2018-06-29 22:46:26 +020054 boost::apply_visitor(Interpreter(parser, *yangschema), cmd);
Václav Kubernátff2c9f62018-05-16 20:26:31 +020055 } catch (InvalidCommandException& ex) {
56 std::cerr << ex.what() << std::endl;
57 }
58 }
59
Jan Kundrátdc2b0722018-03-02 14:13:37 +010060 return 0;
61}