blob: a164a8ed210e1729476fac962886d8b8f5e4cb7f [file] [log] [blame]
Junxiao Shid243d712016-08-19 06:45:31 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa997d292017-08-24 20:16:59 -04002/*
Davide Pesaventoe0bae0f2018-02-17 22:07:52 -05003 * Copyright (c) 2014-2018, Regents of the University of California,
Junxiao Shid243d712016-08-19 06:45:31 +00004 * 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 Shi6c135622016-11-21 14:30:33 +000027#include "help.hpp"
Junxiao Shid243d712016-08-19 06:45:31 +000028#include "core/version.hpp"
29
Davide Pesaventoa997d292017-08-24 20:16:59 -040030#include <iostream>
31
Junxiao Shid243d712016-08-19 06:45:31 +000032namespace nfd {
33namespace tools {
34namespace nfdc {
35
Junxiao Shid243d712016-08-19 06:45:31 +000036static int
37main(int argc, char** argv)
38{
Junxiao Shi64567bb2016-09-04 16:00:27 +000039 std::vector<std::string> args(argv + 1, argv + argc);
40
Junxiao Shi6c135622016-11-21 14:30:33 +000041 CommandParser parser;
42 registerCommands(parser);
43
Davide Pesaventoe0bae0f2018-02-17 22:07:52 -050044 if (args.empty() || args[0] == "-h" || args[0] == "--help") {
Junxiao Shi6c135622016-11-21 14:30:33 +000045 helpList(std::cout, parser);
Junxiao Shid243d712016-08-19 06:45:31 +000046 return 0;
47 }
48
Davide Pesaventoe0bae0f2018-02-17 22:07:52 -050049 if (args[0] == "-V" || args[0] == "--version") {
Junxiao Shid243d712016-08-19 06:45:31 +000050 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
51 return 0;
52 }
53
Junxiao Shi737c43c2016-09-14 02:51:44 +000054 std::string noun, verb;
Junxiao Shi64567bb2016-09-04 16:00:27 +000055 CommandArguments ca;
Junxiao Shi737c43c2016-09-14 02:51:44 +000056 ExecuteCommand execute;
Junxiao Shi64567bb2016-09-04 16:00:27 +000057 try {
Davide Pesaventoe0bae0f2018-02-17 22:07:52 -050058 std::tie(noun, verb, ca, execute) = parser.parse(std::move(args), ParseMode::ONE_SHOT);
Junxiao Shi64567bb2016-09-04 16:00:27 +000059 }
60 catch (const std::invalid_argument& e) {
61 std::cerr << e.what() << std::endl;
Junxiao Shibf6acd52016-09-14 03:57:57 +000062 return 2;
Junxiao Shi331ade72016-08-19 14:07:19 +000063 }
64
Junxiao Shi737c43c2016-09-14 02:51:44 +000065 try {
Junxiao Shi1f481fa2017-01-26 15:14:43 +000066 Face face;
67 KeyChain keyChain;
68 Controller controller(face, keyChain);
69 ExecuteContext ctx{noun, verb, ca, 0, std::cout, std::cerr, face, keyChain, controller};
Junxiao Shi88a062d2017-01-26 03:10:05 +000070 execute(ctx);
71 return ctx.exitCode;
Junxiao Shi737c43c2016-09-14 02:51:44 +000072 }
73 catch (const std::exception& e) {
74 std::cerr << e.what() << std::endl;
75 return 1;
76 }
Junxiao Shid243d712016-08-19 06:45:31 +000077}
78
79} // namespace nfdc
80} // namespace tools
81} // namespace nfd
82
83int
84main(int argc, char** argv)
85{
86 return nfd::tools::nfdc::main(argc, argv);
87}