blob: 57ad8bab1018cc239b1310f717e5a1693b25a1a2 [file] [log] [blame]
Yingdi Yuc9843cf2014-08-04 17:52:19 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
Yingdi Yuc9843cf2014-08-04 17:52:19 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * This file is part of NDN DeLorean, An Authentication System for Data Archives in
6 * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
7 * and contributors.
Yingdi Yuc9843cf2014-08-04 17:52:19 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * NDN DeLorean is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
Yingdi Yuc9843cf2014-08-04 17:52:19 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Yingdi Yuc9843cf2014-08-04 17:52:19 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * You should have received a copy of the GNU General Public License along with NDN
19 * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yuc9843cf2014-08-04 17:52:19 -070020 */
21
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070022#include "common.hpp"
Yingdi Yu6ff31932015-03-23 13:30:07 -070023#include "../core/logger.hpp"
24
25#include <boost/program_options/options_description.hpp>
26#include <boost/program_options/variables_map.hpp>
27#include <boost/program_options/parsers.hpp>
28#include <boost/filesystem.hpp>
29
Yingdi Yuc9843cf2014-08-04 17:52:19 -070030int
31main(int argc, char** argv)
32{
Yingdi Yu6ff31932015-03-23 13:30:07 -070033 namespace po = boost::program_options;
34 namespace fs = boost::filesystem;
35
36 std::string configFile;
37
38 po::options_description description("General Usage\n"
39 " nsl [-h] [-c config]\n"
40 "General options");
41 description.add_options()
42 ("help,h", "produce help message")
43 ("config,c", po::value<std::string>(&configFile))
44 ;
45
46 po::variables_map vm;
47 try {
48 po::store(po::parse_command_line(argc, argv, description), vm);
49 po::notify(vm);
50 }
51 catch (const std::exception& e) {
52 std::cerr << "ERROR: " << e.what() << std::endl;
53 std::cerr << description << std::endl;
54 return 1;
55 }
56
57 if (vm.count("help") != 0) {
58 std::cerr << description << std::endl;
59 return 0;
60 }
61
62 if (vm.count("config") == 0) {
63
64 if (!getenv("HOME")) {
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070065 configFile = NDN_DELOREAN_DEFAULT_CONFIG_FILE;
Yingdi Yu6ff31932015-03-23 13:30:07 -070066 }
67 else {
68 configFile = getenv("HOME");
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070069 configFile += "/.ndn/ndn-delorean.conf";
Yingdi Yu6ff31932015-03-23 13:30:07 -070070 }
71
72 if (!fs::exists(fs::path(configFile))) {
73 std::cerr << "ERROR: config file is not available: " << configFile << std::endl;
74 return 1;
75 }
76 }
77
78 try {
79 ndn::Face face;
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070080 ndn::delorean::Logger(face, configFile);
Yingdi Yu6ff31932015-03-23 13:30:07 -070081 face.processEvents();
82 }
83 catch (std::runtime_error& e) {
84 std::cerr << e.what() << std::endl;
85 return 1;
86 }
87
Yingdi Yuc9843cf2014-08-04 17:52:19 -070088 return 0;
89}