From 0061d0b8802a8cdf7869b2a237fac732f812b13c Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 15 Dec 2011 14:54:40 +0100 Subject: [PATCH 1/3] Support {-V|--version} and adjust usage syntax --- configure.in | 5 ++++- thin_dump.cc | 24 +++++++++++++++--------- thin_repair.cc | 26 +++++++++++++++++++++++++- thin_restore.cc | 24 +++++++++++++++--------- 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/configure.in b/configure.in index d24cdc2..ff10b34 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/thin_dump.cc b/thin_dump.cc index 6577503..f70a95f 100644 --- a/thin_dump.cc +++ b/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] " << 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; } diff --git a/thin_repair.cc b/thin_repair.cc index 55e899d..8e47efb 100644 --- a/thin_repair.cc +++ b/thin_repair.cc @@ -17,9 +17,11 @@ // . #include +#include #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 << " " << 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); diff --git a/thin_restore.cc b/thin_restore.cc index 4fd5ec6..43aa3cc 100644 --- a/thin_restore.cc +++ b/thin_restore.cc @@ -21,6 +21,7 @@ #include "metadata.h" #include "restore_emitter.h" #include "xml_format.h" +#include "version.h" #include #include @@ -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; } From 3d52279dc3b7676f82fdb056be884b066d2bb598 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 15 Dec 2011 14:58:25 +0100 Subject: [PATCH 2/3] version.h.in --- version.h.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 version.h.in diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000..3a42ab6 --- /dev/null +++ b/version.h.in @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2011 Red Hat, Inc. All rights reserved. + * + * This file is part of Thin Provisioing Tools. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU General Public License v.3. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _THIN_PROVISIONING_TOOLS_VERSION_H +/** + * The Thin Provisioning Tools version number + */ + +#define THIN_PROVISIONING_TOOLS_VERSION @THIN_PROVISIONING_TOOLS_VERSION@ +#endif From 7ba9183d347364b588112c33836e1ed870cd80c4 Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Thu, 15 Dec 2011 15:17:49 +0100 Subject: [PATCH 3/3] Use basename(argv[0]) where appropriate to avoid hard coded tool name --- thin_dump.cc | 5 +++-- thin_repair.cc | 5 +++-- thin_restore.cc | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/thin_dump.cc b/thin_dump.cc index f70a95f..c01ce62 100644 --- a/thin_dump.cc +++ b/thin_dump.cc @@ -18,6 +18,7 @@ #include #include +#include #include "human_readable_format.h" #include "metadata_dumper.h" @@ -74,7 +75,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch(c) { case 'h': - usage(argv[0]); + usage(basename(argv[0])); return 0; case 'f': format = optarg; @@ -89,7 +90,7 @@ int main(int argc, char **argv) } if (argc == 1) { - usage(argv[0]); + usage(basename(argv[0])); return 1; } diff --git a/thin_repair.cc b/thin_repair.cc index 8e47efb..30b9c7e 100644 --- a/thin_repair.cc +++ b/thin_repair.cc @@ -18,6 +18,7 @@ #include #include +#include #include "metadata.h" #include "metadata_checker.h" @@ -61,7 +62,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch(c) { case 'h': - usage(argv[0]); + usage(basename(argv[0])); return 0; case 'V': cerr << THIN_PROVISIONING_TOOLS_VERSION << endl; @@ -70,7 +71,7 @@ int main(int argc, char **argv) } if (argc != 2) { - usage(argv[0]); + usage(basename(argv[0])); exit(1); } diff --git a/thin_restore.cc b/thin_restore.cc index 43aa3cc..041e4e7 100644 --- a/thin_restore.cc +++ b/thin_restore.cc @@ -26,6 +26,7 @@ #include #include #include +#include using namespace persistent_data; using namespace std; @@ -78,7 +79,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch(c) { case 'h': - usage(argv[0]); + usage(basename(argv[0])); return 0; case 'i': input = optarg; @@ -93,7 +94,7 @@ int main(int argc, char **argv) } if (argc == 1) { - usage(argv[0]); + usage(basename(argv[0])); return 1; }