[thin_delta] read in the snaps and dev
This commit is contained in:
parent
b03fa373a1
commit
e851b35954
@ -12,7 +12,7 @@ Feature: thin_delta
|
|||||||
Then it should pass with:
|
Then it should pass with:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Usage: thin_delta [options]
|
Usage: thin_delta [options] --snap1 <snap> --snap2 <snap> <device or file>
|
||||||
Options:
|
Options:
|
||||||
{-h|--help}
|
{-h|--help}
|
||||||
{-V|--version}
|
{-V|--version}
|
||||||
@ -22,7 +22,7 @@ Feature: thin_delta
|
|||||||
When I run `thin_delta -h`
|
When I run `thin_delta -h`
|
||||||
Then it should pass with:
|
Then it should pass with:
|
||||||
"""
|
"""
|
||||||
Usage: thin_delta [options]
|
Usage: thin_delta [options] --snap1 <snap> --snap2 <snap> <device or file>
|
||||||
Options:
|
Options:
|
||||||
{-h|--help}
|
{-h|--help}
|
||||||
{-V|--version}
|
{-V|--version}
|
||||||
@ -31,3 +31,24 @@ Feature: thin_delta
|
|||||||
Scenario: Unrecognised option should cause failure
|
Scenario: Unrecognised option should cause failure
|
||||||
When I run `thin_delta --unleash-the-hedeghogs`
|
When I run `thin_delta --unleash-the-hedeghogs`
|
||||||
Then it should fail
|
Then it should fail
|
||||||
|
|
||||||
|
Scenario: --snap1 must be specified
|
||||||
|
When I run `thin_delta --snap2 45 foo`
|
||||||
|
Then it should fail with:
|
||||||
|
"""
|
||||||
|
--snap1 not specified.
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: --snap2 must be specified
|
||||||
|
When I run `thin_delta --snap1 45 foo`
|
||||||
|
Then it should fail with:
|
||||||
|
"""
|
||||||
|
--snap2 not specified.
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: device must be specified
|
||||||
|
When I run `thin_delta --snap1 45 --snap2 50`
|
||||||
|
Then it should fail with:
|
||||||
|
"""
|
||||||
|
No input device provided.
|
||||||
|
"""
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
@ -9,41 +11,102 @@ using namespace std;
|
|||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void usage(ostream &out, string const &cmd) {
|
class application {
|
||||||
out << "Usage: " << cmd << " [options]" << endl
|
public:
|
||||||
<< "Options:" << endl
|
application(string const &cmd)
|
||||||
<< " {-h|--help}" << endl
|
: cmd_(cmd) {
|
||||||
<< " {-V|--version}" << endl;
|
}
|
||||||
}
|
|
||||||
|
void usage(ostream &out) {
|
||||||
|
out << "Usage: " << cmd_ << " [options] --snap1 <snap> --snap2 <snap> <device or file>" << endl
|
||||||
|
<< "Options:" << endl
|
||||||
|
<< " {-h|--help}" << endl
|
||||||
|
<< " {-V|--version}" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void die(string const &msg) {
|
||||||
|
cerr << msg << endl;
|
||||||
|
usage(cerr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned parse_snap(string const &str) {
|
||||||
|
try {
|
||||||
|
return boost::lexical_cast<unsigned>(str);
|
||||||
|
|
||||||
|
} catch (...) {
|
||||||
|
ostringstream out;
|
||||||
|
out << "Couldn't parse snapshot designator: '" << str << "'";
|
||||||
|
die(out.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; // never get here
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
string cmd_;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct flags {
|
||||||
|
boost::optional<string> dev;
|
||||||
|
boost::optional<unsigned> snap1;
|
||||||
|
boost::optional<unsigned> snap2;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
|
// FIXME: add metadata snap switch
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
flags fs;
|
||||||
|
application app(basename(argv[0]));
|
||||||
|
|
||||||
char const shortopts[] = "hV";
|
char const shortopts[] = "hV";
|
||||||
option const longopts[] = {
|
option const longopts[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "version", no_argument, NULL, 'V' }
|
{ "version", no_argument, NULL, 'V' },
|
||||||
|
{ "snap1", required_argument, NULL, 1 },
|
||||||
|
{ "snap2", required_argument, NULL, 2 },
|
||||||
};
|
};
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(cout, basename(argv[0]));
|
app.usage(cout);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case 'V':
|
case 'V':
|
||||||
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
fs.snap1 = app.parse_snap(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
fs.snap2 = app.parse_snap(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage(cerr, basename(argv[0]));
|
app.usage(cerr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc == optind)
|
||||||
|
app.die("No input device provided.");
|
||||||
|
else
|
||||||
|
fs.dev = argv[optind];
|
||||||
|
|
||||||
|
if (!fs.snap1)
|
||||||
|
app.die("--snap1 not specified.");
|
||||||
|
|
||||||
|
if (!fs.snap2)
|
||||||
|
app.die("--snap2 not specified.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user