Support {-V|--version} and adjust usage syntax
This commit is contained in:
parent
8b65410f37
commit
0061d0b880
@ -122,7 +122,7 @@ dnl -- Check for getopt
|
||||
AC_CHECK_HEADERS(getopt.h, AC_DEFINE([HAVE_GETOPTLONG], 1, [Define to 1 if getopt_long is available.]))
|
||||
|
||||
################################################################################
|
||||
VERSION="\"`cat "$srcdir"/VERSION 2>/dev/null || echo Unknown`\""
|
||||
THIN_PROVISIONING_TOOLS_VERSION="\"`cat "$srcdir"/VERSION 2>/dev/null || echo Unknown`\""
|
||||
|
||||
VER=`cat "$srcdir"/VERSION`
|
||||
RELEASE_DATE="\"`echo $VER | $SED 's/.* (//;s/).*//'`\""
|
||||
@ -139,6 +139,8 @@ AC_SUBST(CXXOPTIMISE_FLAG)
|
||||
AC_SUBST(INSTALL)
|
||||
AC_SUBST(prefix)
|
||||
AC_SUBST(RELEASE_DATE)
|
||||
AC_SUBST(RELEASE_DATE)
|
||||
AC_SUBST(THIN_PROVISIONING_TOOLS_VERSION)
|
||||
|
||||
################################################################################
|
||||
dnl -- First and last lines should not contain files to generate in order to
|
||||
@ -146,5 +148,6 @@ dnl -- keep utility scripts running properly
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
unit-tests/Makefile.in
|
||||
version.h
|
||||
])
|
||||
AC_OUTPUT
|
||||
|
24
thin_dump.cc
24
thin_dump.cc
@ -23,6 +23,7 @@
|
||||
#include "metadata_dumper.h"
|
||||
#include "metadata.h"
|
||||
#include "xml_format.h"
|
||||
#include "version.h"
|
||||
|
||||
using namespace persistent_data;
|
||||
using namespace std;
|
||||
@ -47,43 +48,48 @@ namespace {
|
||||
metadata_dump(md, e);
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
cerr << "Usage: thin_dump [options] <metadata device or file>" << endl << endl;
|
||||
void usage(string const &cmd) {
|
||||
cerr << "Usage: " << cmd << " [options] {metadata device|file}" << endl << endl;
|
||||
cerr << "Options:" << 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;
|
||||
cerr << " {-h|--help}" << endl;
|
||||
cerr << " {-f|--format} {xml|human_readable}" << endl;
|
||||
cerr << " {-i|--input} {xml|human_readable} input_file" << endl;
|
||||
cerr << " {-V|--version}" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
const char shortopts[] = "hf:i:";
|
||||
const char shortopts[] = "hf:i:V";
|
||||
string filename, format = "xml";
|
||||
const struct option longopts[] = {
|
||||
{ "help", no_argument, NULL, 'h'},
|
||||
{ "format", required_argument, NULL, 'f' },
|
||||
{ "input", required_argument, NULL, 'i'},
|
||||
{ "version", no_argument, NULL, 'V'},
|
||||
{ NULL, no_argument, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
usage();
|
||||
return 1;
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
case 'f':
|
||||
format = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
filename = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
usage();
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,11 @@
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "metadata.h"
|
||||
#include "metadata_checker.h"
|
||||
#include "version.h"
|
||||
|
||||
using namespace persistent_data;
|
||||
using namespace std;
|
||||
@ -39,12 +41,34 @@ namespace {
|
||||
}
|
||||
|
||||
void usage(string const &cmd) {
|
||||
cerr << "Usage: " << cmd << " <metadata device>" << endl;
|
||||
cerr << "Usage: " << cmd << " {device|file}" << endl;
|
||||
cerr << "Options:" << endl;
|
||||
cerr << " {-h|--help}" << endl;
|
||||
cerr << " {-V|--version}" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
const char shortopts[] = "hV";
|
||||
const struct option longopts[] = {
|
||||
{ "help", no_argument, NULL, 'h'},
|
||||
{ "version", no_argument, NULL, 'V'},
|
||||
{ NULL, no_argument, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
case 'V':
|
||||
cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc != 2) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "metadata.h"
|
||||
#include "restore_emitter.h"
|
||||
#include "xml_format.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@ -51,43 +52,48 @@ namespace {
|
||||
#endif
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
cerr << "Usage: thin_restore [options]" << endl << endl;
|
||||
void usage(string const &cmd) {
|
||||
cerr << "Usage: " << cmd << " [options] [file]" << endl << endl;
|
||||
cerr << "Options:" << endl;
|
||||
cerr << " -h [ --help ] Produce help message" << endl;
|
||||
cerr << " -i [ --input ] arg Input file" << endl;
|
||||
cerr << " -o [ --output ] arg Output file" << endl;
|
||||
cerr << " {-h|--help}" << endl;
|
||||
cerr << " {-i|--input}" << endl;
|
||||
cerr << " {-o [ --output} output_file" << endl;
|
||||
cerr << " {-V|--version}" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
const char *shortopts = "hi:o:";
|
||||
const char *shortopts = "hi:o:V";
|
||||
string input, output;
|
||||
const struct option longopts[] = {
|
||||
{ "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, shortopts, longopts, NULL)) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
usage();
|
||||
return 1;
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
case 'i':
|
||||
input = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
output = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
usage();
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user