add -h --help flag
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
@@ -155,6 +157,11 @@ int main(int argc, char **argv) {
|
|||||||
std::string stdoutPath;
|
std::string stdoutPath;
|
||||||
std::string stderrPath;
|
std::string stderrPath;
|
||||||
int iters = 1;
|
int iters = 1;
|
||||||
|
int sleepMs = 1000;
|
||||||
|
|
||||||
|
bool help = false;
|
||||||
|
|
||||||
|
auto helpMode = option("-h", "--help").set(help).doc("show help");
|
||||||
|
|
||||||
auto shieldGroup = ((option("-u").doc("number of unshielded CPUs") &
|
auto shieldGroup = ((option("-u").doc("number of unshielded CPUs") &
|
||||||
value("INT", numUnshielded)) |
|
value("INT", numUnshielded)) |
|
||||||
@@ -184,8 +191,11 @@ int main(int argc, char **argv) {
|
|||||||
(option("--stderr").doc("redirect child stderr") &
|
(option("--stderr").doc("redirect child stderr") &
|
||||||
value("PATH", stderrPath)));
|
value("PATH", stderrPath)));
|
||||||
|
|
||||||
auto cli = ((noModMode | modMode),
|
auto cli =
|
||||||
(option("-n").doc("run multiple times") & value("INT", iters)),
|
helpMode |
|
||||||
|
((noModMode | modMode),
|
||||||
|
(option("--sleep-ms").doc("sleep before run") & value("INT", sleepMs)),
|
||||||
|
(option("-n").doc("run multiple times") & value("INT", iters)), helpMode,
|
||||||
// run everything after "--"
|
// run everything after "--"
|
||||||
required("--") & greedy(values("cmd", program))
|
required("--") & greedy(values("cmd", program))
|
||||||
|
|
||||||
@@ -197,6 +207,12 @@ int main(int argc, char **argv) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (help) {
|
||||||
|
auto fmt = doc_formatting{}.doc_column(31);
|
||||||
|
std::cout << make_man_page(cli, argv[0], fmt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// open the redirect files, if needed
|
// open the redirect files, if needed
|
||||||
int errf = 0;
|
int errf = 0;
|
||||||
int outf = 0;
|
int outf = 0;
|
||||||
@@ -333,6 +349,12 @@ int main(int argc, char **argv) {
|
|||||||
PERFECT(perfect::drop_caches());
|
PERFECT(perfect::drop_caches());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sleep before each run
|
||||||
|
if (sleepMs) {
|
||||||
|
std::cerr << "sleep " << sleepMs << " ms before run\n";
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(sleepMs));
|
||||||
|
}
|
||||||
|
|
||||||
std::cerr << "exec ";
|
std::cerr << "exec ";
|
||||||
for (size_t i = 0; i < args.size() - 1; ++i) {
|
for (size_t i = 0; i < args.size() - 1; ++i) {
|
||||||
std::cerr << args[i] << " ";
|
std::cerr << args[i] << " ";
|
||||||
|
Reference in New Issue
Block a user