Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2020, Regents of the University of California |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 4 | * |
| 5 | * NAC library is free software: you can redistribute it and/or modify it under the |
| 6 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 7 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 11 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 14 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 15 | * <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * See AUTHORS.md for complete list of NAC library authors and contributors. |
| 18 | */ |
| 19 | |
| 20 | #include "ndn-nac.hpp" |
| 21 | #include "version.hpp" |
| 22 | |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 23 | #include <boost/exception/diagnostic_information.hpp> |
| 24 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 25 | #include <ndn-cxx/util/logger.hpp> |
| 26 | |
| 27 | NDN_LOG_INIT(nac.Cmd); |
| 28 | |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 29 | const char NAC_HELP_TEXT[] = R"STR( |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 30 | help Show all commands |
| 31 | version Show version and exit |
| 32 | dump-kek Dump KEK |
| 33 | add-member Create KDK for the member |
| 34 | )STR"; |
| 35 | |
| 36 | int |
| 37 | main(int argc, char** argv) |
| 38 | { |
| 39 | if (argc < 2) { |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 40 | std::cerr << NAC_HELP_TEXT << std::endl; |
| 41 | return 2; |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | using namespace ndn::nac; |
| 45 | |
| 46 | std::string command(argv[1]); |
| 47 | try { |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 48 | if (command == "help") { std::cout << NAC_HELP_TEXT << std::endl; } |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 49 | else if (command == "version") { std::cout << NDN_NAC_VERSION_BUILD_STRING << std::endl; } |
| 50 | else if (command == "dump-kek") { return nac_dump_kek(argc - 1, argv + 1); } |
| 51 | else if (command == "add-member") { return nac_add_member(argc - 1, argv + 1); } |
| 52 | else { |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 53 | std::cerr << "ERROR: Unknown command '" << command << "'\n" |
| 54 | << "\n" |
| 55 | << NAC_HELP_TEXT << std::endl; |
| 56 | return 2; |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | catch (const std::exception& e) { |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 60 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 61 | NDN_LOG_ERROR(boost::diagnostic_information(e)); |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |