Remove po:: namespace and fix short options in thin_dump.cc. Switch thin_restore away from boost_rogram_options to getopt_long.

This commit is contained in:
Heinz Mauelshagen 2011-12-14 17:38:26 +01:00
parent bad6aff58b
commit 6ba6d6a28c
2 changed files with 38 additions and 32 deletions

View File

@ -24,14 +24,10 @@
#include "metadata.h"
#include "xml_format.h"
#include <boost/program_options.hpp>
using namespace persistent_data;
using namespace std;
using namespace thin_provisioning;
namespace po = boost::program_options;
//----------------------------------------------------------------
namespace {
@ -54,7 +50,7 @@ namespace {
void usage(void) {
cerr << "Usage: thin_dump [options] <metadata device or file>" << endl << endl;
cerr << "Options:" << endl;
cerr << " --help Produce help message" << endl;
cerr << " -h [ --help ] Produce help message" << endl;
cerr << " -f [ --format ] arg (=xml) Select format (human_readable|xml)" << endl;
cerr << " -i [ --input ] arg Input file" << endl;
}
@ -63,7 +59,7 @@ namespace {
int main(int argc, char **argv)
{
int c;
const char shortopts[] = "hfi";
const char shortopts[] = "hf:i:";
string filename, format = "xml";
const struct option longopts[] = {
{ "help", no_argument, NULL, 'h'},

View File

@ -24,14 +24,12 @@
#include <fstream>
#include <iostream>
#include <boost/program_options.hpp>
#include <getopt.h>
using namespace persistent_data;
using namespace std;
using namespace thin_provisioning;
namespace po = boost::program_options;
//----------------------------------------------------------------
namespace {
@ -53,45 +51,57 @@ namespace {
#endif
}
void usage(po::options_description const &desc) {
void usage(void) {
cerr << "Usage: thin_restore [options]" << endl << endl;
cerr << desc;
cerr << "Options:" << endl;
cerr << " -h [ --help ] Produce help message" << endl;
cerr << " -i [ --input ] arg Input file" << endl;
cerr << " -o [ --output ] arg Output file" << endl;
}
}
int main(int argc, char **argv)
{
po::options_description desc("Options");
desc.add_options()
("help", "Produce help message")
("input,i", po::value<string>(), "Input file")
("output,o", po::value<string>(), "Output file")
;
int c;
const char *shortopts = "hi:o:";
string input, output;
const struct option longopts[] = {
{ "help", no_argument, NULL, 'h'},
{ "input", required_argument, NULL, 'i' },
{ "output", required_argument, NULL, 'o'},
{ NULL, no_argument, NULL, 0 }
};
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
po::notify(vm);
if (vm.count("help")) {
usage(desc);
return 0;
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch(c) {
case 'h':
usage();
return 1;
case 'i':
input = optarg;
break;
case 'o':
output = optarg;
break;
}
}
if (vm.count("input") != 1) {
cerr << "No input file provided." << endl;
usage(desc);
if (argc == 1) {
usage();
return 1;
}
if (vm.count("output") != 1) {
cerr << "No output file provided." << endl;
usage(desc);
if (input.empty()) {
cerr << "No input file name" << endl;
return 1;
}
restore(vm["input"].as<string>(),
vm["output"].as<string>());
if (output.empty()) {
cerr << "No output file name" << endl;
return 1;
}
restore(input, output);
return 0;
}