blob: 85fe1e9433f16f155930ba2bf5533ffba3742fcc [file] [log] [blame]
Junxiao Shid243d712016-08-19 06:45:31 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Junxiao Shi64567bb2016-09-04 16:00:27 +000026#include "available-commands.hpp"
Junxiao Shid243d712016-08-19 06:45:31 +000027#include "legacy-nfdc.hpp"
28#include "core/version.hpp"
29
Junxiao Shid243d712016-08-19 06:45:31 +000030namespace nfd {
31namespace tools {
32namespace nfdc {
33
Junxiao Shid243d712016-08-19 06:45:31 +000034static int
35main(int argc, char** argv)
36{
Junxiao Shi64567bb2016-09-04 16:00:27 +000037 std::vector<std::string> args(argv + 1, argv + argc);
38
39 if (args.empty() || args[0] == "-h") {
Junxiao Shi2f741322016-08-29 00:53:18 +000040 legacyNfdcUsage();
Junxiao Shid243d712016-08-19 06:45:31 +000041 return 0;
42 }
43
Junxiao Shi64567bb2016-09-04 16:00:27 +000044 if (args[0] == "-V") {
Junxiao Shid243d712016-08-19 06:45:31 +000045 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
46 return 0;
47 }
48
Junxiao Shi64567bb2016-09-04 16:00:27 +000049 CommandParser parser;
50 registerCommands(parser);
51 CommandParser::Execute* execute = nullptr;
52 CommandArguments ca;
53 try {
54 std::tie(execute, ca) = parser.parse(args, ParseMode::ONE_SHOT);
55 }
56 catch (const std::invalid_argument& e) {
57 std::cerr << e.what() << std::endl;
58 return 1;
Junxiao Shi331ade72016-08-19 14:07:19 +000059 }
60
Junxiao Shi64567bb2016-09-04 16:00:27 +000061 ///\todo create Face and KeyChain here
62 (*execute)(ca);
63 ///\todo call processEvents here
64 ///\todo return proper exit code here, instead of using exit() in subcommand
65 return 0;
Junxiao Shid243d712016-08-19 06:45:31 +000066}
67
68} // namespace nfdc
69} // namespace tools
70} // namespace nfd
71
72int
73main(int argc, char** argv)
74{
75 return nfd::tools::nfdc::main(argc, argv);
76}