Skip to content

Commit

Permalink
Rudimentary Help
Browse files Browse the repository at this point in the history
When -h is passed, print a rudimentary help message and exit.
  • Loading branch information
cbreak-black committed Dec 25, 2014
1 parent 6eedb0f commit a0cf42c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
34 changes: 28 additions & 6 deletions InvariantDisks/IDCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace ID
m_impl->signalSourceINT = createSourceSignal(SIGINT, this, stopHandler);
m_impl->signalSourceTERM = createSourceSignal(SIGTERM, this, stopHandler);
// UI
std::cout << "InvariantDisk " << GIT_VERSION << std::endl;
showVersion();
parse(argc, argv);
}

Expand All @@ -67,6 +67,13 @@ namespace ID

int CLI::exec()
{
// Print help and terminate
if (m_impl->showHelp)
{
showHelp();
return 0;
}
// Start runloop
{
std::lock_guard<std::mutex> lock(m_impl->mutex);
if (m_impl->runloop)
Expand Down Expand Up @@ -101,6 +108,20 @@ namespace ID
std::function<void(char **)> func;
};

void CLI::showVersion() const
{
std::cout << "InvariantDisk " << GIT_VERSION << std::endl;
}

void CLI::showHelp() const
{
std::cout << "Usage: InvariantDisks [-hv] [-p <basePath>] [-t <timeoutMS>]\n";
std::cout << "\t-h:\tprint help and exit\n";
std::cout << "\t-v:\tverbose logging\n";
std::cout << "\t-p <basePath>:\tset base path for symlinks (" << m_impl->basePath << ")\n";
std::cout << "\t-t <timeoutMS>:\tset idle timeout (" << m_impl->idleTimeoutNS/1000000 << " ms)\n";
}

void CLI::parse(int & argc, char ** argv)
{
// Command Line Parsing
Expand All @@ -112,14 +133,15 @@ namespace ID
{"-t", { 1, [&](char ** a){
try
{
m_impl->idleTimeoutNS = std::stol(a[1])*1000000;
int64_t timeoutInNS = std::stol(a[1])*1000000ll;
if (timeoutInNS < 0)
throw std::out_of_range("negative");
m_impl->idleTimeoutNS = timeoutInNS;
}
catch (...)
catch (std::exception const & e)
{
Throw<Exception>() << "Idle Timeout " << a[1] << " is not a number";
Throw<Exception>() << "Idle Timeout " << a[1] << " is not a valid timeout: " << e.what();
}
if (m_impl->idleTimeoutNS < 0)
Throw<Exception>() << "Idle Timeout " << a[1] << " is out of range";
}}}
};
for (int argIdx = 0; argIdx < argc; ++argIdx)
Expand Down
2 changes: 2 additions & 0 deletions InvariantDisks/IDCLI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace ID
void stop();

private:
void showVersion() const;
void showHelp() const;
void parse(int & argc, char ** argv);

private:
Expand Down

0 comments on commit a0cf42c

Please sign in to comment.