tools: replace most ndnsec shell wrappers with symlinks
Change-Id: I40488dddaaee13ee4391e906646b9f651b26c2de
diff --git a/tools/ndnsec/main.cpp b/tools/ndnsec/main.cpp
index c0be01b..9c8e64e 100644
--- a/tools/ndnsec/main.cpp
+++ b/tools/ndnsec/main.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -25,6 +25,7 @@
#include "ndn-cxx/version.hpp"
#include <boost/exception/diagnostic_information.hpp>
+#include <boost/filesystem/path.hpp>
#include <iostream>
NDN_LOG_INIT(ndnsec);
@@ -52,29 +53,39 @@
int
main(int argc, char* argv[])
{
- if (argc < 2) {
+ boost::filesystem::path p(argv[0]);
+ std::string basename(p.filename().string());
+ std::string command;
+ if (basename.rfind("ndnsec-", 0) == 0) {
+ command = basename.substr(std::strlen("ndnsec-"));
+ }
+ else if (argc >= 2) {
+ command = argv[1];
+ argc--;
+ argv++;
+ }
+ else {
std::cerr << NDNSEC_HELP_TEXT << std::endl;
return 2;
}
+ NDN_LOG_TRACE("Command: " << command);
- using namespace ndn::ndnsec;
-
- std::string command(argv[1]);
try {
+ using namespace ndn::ndnsec;
if (command == "help") { std::cout << NDNSEC_HELP_TEXT << std::endl; }
else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING << std::endl; }
- else if (command == "list") { return ndnsec_list(argc - 1, argv + 1); }
- else if (command == "get-default") { return ndnsec_get_default(argc - 1, argv + 1); }
- else if (command == "set-default") { return ndnsec_set_default(argc - 1, argv + 1); }
- else if (command == "delete") { return ndnsec_delete(argc - 1, argv + 1); }
- else if (command == "key-gen") { return ndnsec_key_gen(argc - 1, argv + 1); }
- else if (command == "sign-req") { return ndnsec_sign_req(argc - 1, argv + 1); }
- else if (command == "cert-gen") { return ndnsec_cert_gen(argc - 1, argv + 1); }
- else if (command == "cert-dump") { return ndnsec_cert_dump(argc - 1, argv + 1); }
- else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); }
- else if (command == "export") { return ndnsec_export(argc - 1, argv + 1); }
- else if (command == "import") { return ndnsec_import(argc - 1, argv + 1); }
- else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
+ else if (command == "list") { return ndnsec_list(argc, argv); }
+ else if (command == "get-default") { return ndnsec_get_default(argc, argv); }
+ else if (command == "set-default") { return ndnsec_set_default(argc, argv); }
+ else if (command == "delete") { return ndnsec_delete(argc, argv); }
+ else if (command == "key-gen") { return ndnsec_key_gen(argc, argv); }
+ else if (command == "sign-req") { return ndnsec_sign_req(argc, argv); }
+ else if (command == "cert-gen") { return ndnsec_cert_gen(argc, argv); }
+ else if (command == "cert-dump") { return ndnsec_cert_dump(argc, argv); }
+ else if (command == "cert-install") { return ndnsec_cert_install(argc, argv); }
+ else if (command == "export") { return ndnsec_export(argc, argv); }
+ else if (command == "import") { return ndnsec_import(argc, argv); }
+ else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc, argv); }
else {
std::cerr << "ERROR: Unknown command '" << command << "'\n"
<< "\n"
diff --git a/tools/ndnsec/wscript b/tools/ndnsec/wscript
index 9f61ae4..caac9fc 100644
--- a/tools/ndnsec/wscript
+++ b/tools/ndnsec/wscript
@@ -8,7 +8,13 @@
features='pch',
headers='ndnsec-pch.hpp',
use='ndn-cxx')
+
bld.program(name='tool-ndnsec',
target=top + 'bin/ndnsec',
source=['main.cpp'],
use='tool-ndnsec-objects')
+
+ for cmd in ('list', 'get-default', 'set-default', 'delete',
+ 'key-gen', 'sign-req', 'cert-gen', 'cert-install',
+ 'cert-dump', 'export', 'import', 'unlock-tpm'):
+ bld.symlink_as('${BINDIR}/ndnsec-%s' % cmd, 'ndnsec')