blob: 0ebe9ed39a246510de65f237f067fa5e7abc434a [file] [log] [blame]
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2018, Regents of the University of California
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
23#include <boost/exception/get_error_info.hpp>
24#include <ndn-cxx/util/logger.hpp>
25
26NDN_LOG_INIT(nac.Cmd);
27
28std::string nac_helper = R"STR(
29 help Show all commands
30 version Show version and exit
31 dump-kek Dump KEK
32 add-member Create KDK for the member
33)STR";
34
35int
36main(int argc, char** argv)
37{
38 if (argc < 2) {
39 std::cerr << nac_helper << std::endl;
40 return 1;
41 }
42
43 using namespace ndn::nac;
44
45 std::string command(argv[1]);
46 try {
47 if (command == "help") { std::cout << nac_helper << std::endl; }
48 else if (command == "version") { std::cout << NDN_NAC_VERSION_BUILD_STRING << std::endl; }
49 else if (command == "dump-kek") { return nac_dump_kek(argc - 1, argv + 1); }
50 else if (command == "add-member") { return nac_add_member(argc - 1, argv + 1); }
51 else {
52 std::cerr << nac_helper << std::endl;
53 return 1;
54 }
55 }
56 catch (const std::exception& e) {
57
58 std::cerr << "ERROR: " << e.what();
59
60 std::ostringstream extendedError;
61 const char* const* file = boost::get_error_info<boost::throw_file>(e);
62 const int* line = boost::get_error_info<boost::throw_line>(e);
63 const char* const* func = boost::get_error_info<boost::throw_function>(e);
64 if (file && line) {
65 extendedError << " [from " << *file << ":" << *line;
66 if (func) {
67 extendedError << " in " << *func;
68 }
69 extendedError << "]";
70 }
71 NDN_LOG_ERROR(e.what() << extendedError.str());
72 return 1;
73 }
74
75 return 0;
76}