Switch thin_dump.cc from boost command line option parsing to getopt_long

This commit is contained in:
Heinz Mauelshagen 2011-12-14 15:55:50 +01:00
parent 78e37bb234
commit bad6aff58b
2 changed files with 31 additions and 24 deletions

View File

@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include <iostream>
#include <getopt.h>
#include "human_readable_format.h"
#include "metadata_dumper.h"
@ -50,41 +51,48 @@ namespace {
metadata_dump(md, e);
}
void usage(po::options_description const &desc) {
void usage(void) {
cerr << "Usage: thin_dump [options] <metadata device or file>" << endl << endl;
cerr << desc;
cerr << "Options:" << endl;
cerr << " --help Produce help message" << endl;
cerr << " -f [ --format ] arg (=xml) Select format (human_readable|xml)" << endl;
cerr << " -i [ --input ] arg Input file" << endl;
}
}
int main(int argc, char **argv)
{
po::options_description desc("Options");
desc.add_options()
("help", "Produce help message")
("format,f", po::value<string>()->default_value("xml"), "Select format (human_readable|xml)")
("input,i", po::value<string>(), "Input file")
;
int c;
const char shortopts[] = "hfi";
string filename, format = "xml";
const struct option longopts[] = {
{ "help", no_argument, NULL, 'h'},
{ "format", required_argument, NULL, 'f' },
{ "input", required_argument, NULL, 'i'},
{ NULL, no_argument, NULL, 0 }
};
po::positional_options_description p;
p.add("input", -1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).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 'f':
format = optarg;
break;
case 'i':
filename = optarg;
break;
}
}
if (vm.count("input") != 1) {
cerr << "No input file provided." << endl;
usage(desc);
if (argc == 1 ||
filename.empty()) {
usage();
return 1;
}
dump(vm["input"].as<string>(), vm["format"].as<string>());
dump(filename, format);
return 0;
}

View File

@ -21,7 +21,6 @@
#include "metadata.h"
#include "metadata_checker.h"
using namespace boost;
using namespace persistent_data;
using namespace std;
using namespace thin_provisioning;