add program options to thin_dump

This commit is contained in:
Joe Thornber 2011-10-10 15:59:37 +01:00
parent 687525fdb0
commit 8389ca31a8
5 changed files with 54 additions and 19 deletions

View File

@ -19,7 +19,7 @@ OBJECTS=$(subst .cc,.o,$(SOURCE))
TOP_DIR:=$(PWD)
CPPFLAGS=-Wall -g -I$(TOP_DIR)
#CPPFLAGS=-Wall -std=c++0x -g -I$(TOP_DIR)
LIBS=-lstdc++
LIBS=-lstdc++ -lboost_program_options
.PHONEY: test-programs

View File

@ -3,6 +3,7 @@
#include "block.h"
#include "btree.h"
#include "emitter.h"
#include "endian_utils.h"
#include "error_set.h"
#include "metadata_disk_structures.h"
@ -173,7 +174,7 @@ namespace thin_provisioning {
boost::optional<persistent_data::error_set::ptr> check();
// Dumping metadata
void dump();
void dump(emitter::ptr e);
private:
friend class thin;

View File

@ -1,8 +1,5 @@
#include "metadata.h"
#include "human_readable_format.h"
#include "xml_format.h"
using namespace persistent_data;
using namespace thin_provisioning;
@ -124,10 +121,8 @@ namespace {
}
void
metadata::dump()
metadata::dump(emitter::ptr e)
{
emitter::ptr e = create_xml_emitter(cout);
details_extractor::ptr de(new details_extractor);
details_.visit(de);

View File

@ -1,33 +1,70 @@
#include <iostream>
#include "human_readable_format.h"
#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 {
void dump(string const &path) {
void dump(string const &path, string const &format) {
metadata md(path);
//human_readable::ptr emitter(new human_readable);
md.dump();
emitter::ptr e;
if (format == "xml")
e = create_xml_emitter(cout);
else if (format == "human_readable")
e = create_human_readable_emitter(cout);
else {
cerr << "unknown format '" << format << "'" << endl;
exit(1);
}
md.dump(e);
}
void usage(string const &cmd) {
cerr << "Usage: " << cmd << " <metadata device>" << endl;
void usage(po::options_description const &desc) {
cerr << "Usage: thin_dump [options] <metadata device or file>" << endl << endl;
cerr << desc;
}
}
int main(int argc, char **argv)
{
if (argc != 2) {
usage(argv[0]);
exit(1);
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")
;
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;
}
dump(argv[1]);
if (vm.count("input") != 1) {
cerr << "No input file provided." << endl;
usage(desc);
return 1;
}
dump(vm["input"].as<string>(), vm["format"].as<string>());
return 0;
}

View File

@ -6,6 +6,8 @@
using namespace std;
using namespace thin_provisioning;
namespace tp = thin_provisioning;
//----------------------------------------------------------------
namespace {
@ -101,8 +103,8 @@ namespace {
//----------------------------------------------------------------
thin_provisioning::emitter::ptr
thin_provisioning::create_xml_emitter(ostream &out)
tp::emitter::ptr
tp::create_xml_emitter(ostream &out)
{
return emitter::ptr(new xml_emitter(out));
}