diff --git a/features/thin_delta.feature b/features/thin_delta.feature index 9fd55b4..249d4a6 100644 --- a/features/thin_delta.feature +++ b/features/thin_delta.feature @@ -6,3 +6,24 @@ Feature: thin_delta Scenario: print version (--version flag) When I run `thin_delta --version` Then it should pass with version + + Scenario: print help + When I run `thin_delta --help` + Then it should pass with: + + """ + Usage: thin_delta [options] + Options: + {-h|--help} + {-V|--version} + """ + + Scenario: print help + When I run `thin_delta -h` + Then it should pass with: + """ + Usage: thin_delta [options] + Options: + {-h|--help} + {-V|--version} + """ diff --git a/thin-provisioning/thin_delta.cc b/thin-provisioning/thin_delta.cc index 0959c2b..969b714 100644 --- a/thin-provisioning/thin_delta.cc +++ b/thin-provisioning/thin_delta.cc @@ -1,5 +1,6 @@ #include #include +#include #include "version.h" @@ -7,16 +8,32 @@ using namespace std; //---------------------------------------------------------------- +namespace { + void usage(ostream &out, string const &cmd) { + out << "Usage: " << cmd << " [options]" << endl + << "Options:" << endl + << " {-h|--help}" << endl + << " {-V|--version}" << endl; + } +} + +//---------------------------------------------------------------- + int main(int argc, char **argv) { int c; - char const shortopts[] = "V"; + char const shortopts[] = "hV"; option const longopts[] = { - { "version", no_argument, NULL, 'V'} + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' } }; while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { + case 'h': + usage(cout, basename(argv[0])); + return 0; + case 'V': cout << THIN_PROVISIONING_TOOLS_VERSION << endl; return 0;