blob: 685853269d8e9332f92a27cd20c5e8f23d680b06 [file] [log] [blame]
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoc2649492020-12-22 21:43:35 -05002/*
3 * Copyright (c) 2014-2020, Regents of the University of California
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04004 *
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 Pesaventoc2649492020-12-22 21:43:35 -050023#include <boost/exception/diagnostic_information.hpp>
24
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040025#include <ndn-cxx/util/logger.hpp>
26
27NDN_LOG_INIT(nac.Cmd);
28
Davide Pesaventoc2649492020-12-22 21:43:35 -050029const char NAC_HELP_TEXT[] = R"STR(
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040030 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
36int
37main(int argc, char** argv)
38{
39 if (argc < 2) {
Davide Pesaventoc2649492020-12-22 21:43:35 -050040 std::cerr << NAC_HELP_TEXT << std::endl;
41 return 2;
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040042 }
43
44 using namespace ndn::nac;
45
46 std::string command(argv[1]);
47 try {
Davide Pesaventoc2649492020-12-22 21:43:35 -050048 if (command == "help") { std::cout << NAC_HELP_TEXT << std::endl; }
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040049 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 Pesaventoc2649492020-12-22 21:43:35 -050053 std::cerr << "ERROR: Unknown command '" << command << "'\n"
54 << "\n"
55 << NAC_HELP_TEXT << std::endl;
56 return 2;
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040057 }
58 }
59 catch (const std::exception& e) {
Davide Pesaventoc2649492020-12-22 21:43:35 -050060 std::cerr << "ERROR: " << e.what() << std::endl;
61 NDN_LOG_ERROR(boost::diagnostic_information(e));
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040062 return 1;
63 }
64
65 return 0;
66}