Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 1 | /* -*- 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 Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 26 | #include "available-commands.hpp" |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 27 | #include "legacy-nfdc.hpp" |
| 28 | #include "core/version.hpp" |
| 29 | |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 30 | namespace nfd { |
| 31 | namespace tools { |
| 32 | namespace nfdc { |
| 33 | |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 34 | static int |
| 35 | main(int argc, char** argv) |
| 36 | { |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 37 | std::vector<std::string> args(argv + 1, argv + argc); |
| 38 | |
| 39 | if (args.empty() || args[0] == "-h") { |
Junxiao Shi | 2f74132 | 2016-08-29 00:53:18 +0000 | [diff] [blame] | 40 | legacyNfdcUsage(); |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 41 | return 0; |
| 42 | } |
| 43 | |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 44 | if (args[0] == "-V") { |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 45 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 46 | return 0; |
| 47 | } |
| 48 | |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 49 | CommandParser parser; |
| 50 | registerCommands(parser); |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 51 | std::string noun, verb; |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 52 | CommandArguments ca; |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 53 | ExecuteCommand execute; |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 54 | try { |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 55 | std::tie(noun, verb, ca, execute) = parser.parse(args, ParseMode::ONE_SHOT); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 56 | } |
| 57 | catch (const std::invalid_argument& e) { |
| 58 | std::cerr << e.what() << std::endl; |
Junxiao Shi | bf6acd5 | 2016-09-14 03:57:57 +0000 | [diff] [blame] | 59 | return 2; |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 62 | try { |
| 63 | ndn::Face face; |
| 64 | ndn::KeyChain keyChain; |
| 65 | ExecuteContext ctx{noun, verb, ca, face, keyChain}; |
| 66 | return execute(ctx); |
| 67 | } |
| 68 | catch (const std::exception& e) { |
| 69 | std::cerr << e.what() << std::endl; |
| 70 | return 1; |
| 71 | } |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | } // namespace nfdc |
| 75 | } // namespace tools |
| 76 | } // namespace nfd |
| 77 | |
| 78 | int |
| 79 | main(int argc, char** argv) |
| 80 | { |
| 81 | return nfd::tools::nfdc::main(argc, argv); |
| 82 | } |