Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
Jan Kundrát | a274044 | 2018-03-22 16:56:43 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 4 | * |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <docopt.h> |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 10 | #include <iostream> |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 11 | #include "NETCONF_CLI_VERSION.h" |
Václav Kubernát | 96344a1 | 2018-05-28 16:33:39 +0200 | [diff] [blame] | 12 | #include "interpreter.hpp" |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 13 | #include "static_schema.hpp" |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 14 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 15 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 16 | static const char usage[] = |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 17 | R"(CLI interface to remote NETCONF hosts |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 18 | |
| 19 | Usage: |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 20 | netconf-cli |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 21 | netconf-cli (-h | --help) |
| 22 | netconf-cli --version |
| 23 | )"; |
| 24 | |
Václav Kubernát | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 25 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 26 | int 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át | 624a887 | 2018-03-02 17:28:47 +0100 | [diff] [blame] | 33 | std::cout << "Welcome to netconf-cli" << std::endl; |
Václav Kubernát | ff2c9f6 | 2018-05-16 20:26:31 +0200 | [diff] [blame] | 34 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 35 | 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át | ff2c9f6 | 2018-05-16 20:26:31 +0200 | [diff] [blame] | 47 | |
| 48 | while (true) { |
Václav Kubernát | f2e463f | 2018-05-28 15:51:08 +0200 | [diff] [blame] | 49 | std::cout << parser.currentNode() << "> "; |
Václav Kubernát | ff2c9f6 | 2018-05-16 20:26:31 +0200 | [diff] [blame] | 50 | std::string input; |
| 51 | std::getline(std::cin, input); |
| 52 | if (std::cin.eof()) |
| 53 | break; |
| 54 | |
| 55 | try { |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 56 | command_ cmd = parser.parseCommand(input, std::cout); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 57 | boost::apply_visitor(Interpreter(parser, *yangschema), cmd); |
Václav Kubernát | ff2c9f6 | 2018-05-16 20:26:31 +0200 | [diff] [blame] | 58 | } catch (InvalidCommandException& ex) { |
| 59 | std::cerr << ex.what() << std::endl; |
| 60 | } |
| 61 | } |
| 62 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 63 | return 0; |
| 64 | } |