thin-provisioning-tools/caching/cache_restore.cc
2013-08-16 16:29:41 +01:00

83 lines
1.6 KiB
C++

#include "version.h"
#include <getopt.h>
#include <iostream>
#include <libgen.h>
#include <string>
using namespace std;
//----------------------------------------------------------------
namespace {
void usage(ostream &out, string const &cmd) {
out << "Usage: " << cmd << " [options]" << endl
<< "Options:" << endl
<< " {-h|--help}" << endl
<< " {-i|--input} <input xml file>" << endl
<< " {-o|--output} <output device or file>" << endl
<< " {-V|--version}" << endl;
}
}
int main(int argc, char **argv)
{
int c;
string input, output;
char const *prog_name = basename(argv[0]);
char const *short_opts = "hi:o:V";
option const long_opts[] = {
{ "help", no_argument, NULL, 'h'},
{ "input", required_argument, NULL, 'i' },
{ "output", required_argument, NULL, 'o'},
{ "version", no_argument, NULL, 'V'},
{ NULL, no_argument, NULL, 0 }
};
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
switch(c) {
case 'h':
usage(cout, prog_name);
return 0;
case 'i':
input = optarg;
break;
case 'o':
output = optarg;
break;
case 'V':
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
return 0;
default:
usage(cerr, prog_name);
return 1;
}
}
if (argc != optind) {
usage(cerr, prog_name);
return 1;
}
if (input.empty()) {
cerr << "No input file provided." << endl << endl;
usage(cerr, prog_name);
return 1;
}
if (output.empty()) {
cerr << "No output file provided." << endl << endl;
usage(cerr, prog_name);
return 1;
}
return 0;
}
//----------------------------------------------------------------