From: Arvin Schnell Date: Mon, 31 Aug 2020 10:45:39 +0000 (+0200) Subject: - improved error messages for wrong command line options and arguments (bsc#1150156) X-Git-Tag: v0.8.14~32^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F550%2Fhead;p=thirdparty%2Fsnapper.git - improved error messages for wrong command line options and arguments (bsc#1150156) --- diff --git a/client/GlobalOptions.cc b/client/GlobalOptions.cc index 5b170c29..703b5be3 100644 --- a/client/GlobalOptions.cc +++ b/client/GlobalOptions.cc @@ -211,7 +211,7 @@ namespace snapper Ambit ambit; if (!toValue(str, ambit, false)) { - string error = sformat(_("Invalid ambit %s."), str.c_str()) + '\n' + + string error = sformat(_("Invalid ambit '%s'."), str.c_str()) + '\n' + sformat(_("Use %s, %s or %s."), toString(Ambit::AUTO).c_str(), toString(Ambit::CLASSIC).c_str(), toString(Ambit::TRANSACTIONAL).c_str()); diff --git a/client/cmd-create.cc b/client/cmd-create.cc index 2dd8b6ee..2ca14131 100644 --- a/client/cmd-create.cc +++ b/client/cmd-create.cc @@ -23,6 +23,8 @@ #include +#include + #include "utils/text.h" #include "GlobalOptions.h" #include "proxy.h" @@ -73,11 +75,6 @@ namespace snapper }; ParsedOpts opts = get_opts.parse("create", options); - if (get_opts.has_args()) - { - cerr << _("Command 'create' does not take arguments.") << endl; - exit(EXIT_FAILURE); - } enum class CreateType { SINGLE, PRE, POST, PRE_POST }; @@ -105,8 +102,10 @@ namespace snapper type = CreateType::PRE_POST; else { - cerr << _("Unknown type of snapshot.") << endl; - exit(EXIT_FAILURE); + string error = sformat(_("Unknown type '%s'."), opt->second.c_str()) + '\n' + + sformat(_("Use %s, %s, %s or %s."), "single", "pre", "post", "pre-post"); + + SN_THROW(OptionsException(error)); } } @@ -142,26 +141,27 @@ namespace snapper if (type == CreateType::POST && snapshot1 == snapshots.end()) { - cerr << _("Missing or invalid pre-number.") << endl; - exit(EXIT_FAILURE); + SN_THROW(OptionsException(_("Missing or invalid pre-number."))); } if (type == CreateType::PRE_POST && command.empty()) { - cerr << _("Missing command argument.") << endl; - exit(EXIT_FAILURE); + SN_THROW(OptionsException(_("Missing command option."))); } if (type != CreateType::SINGLE && !scd.read_only) { - cerr << _("Option --read-write only supported for snapshots of type single.") << endl; - exit(EXIT_FAILURE); + SN_THROW(OptionsException(_("Option --read-write only supported for snapshots of type single."))); } if (type != CreateType::SINGLE && parent != snapshots.getCurrent()) { - cerr << _("Option --from only supported for snapshots of type single.") << endl; - exit(EXIT_FAILURE); + SN_THROW(OptionsException(_("Option --from only supported for snapshots of type single."))); + } + + if (get_opts.has_args()) + { + SN_THROW(OptionsException(_("Command 'create' does not take arguments."))); } switch (type) diff --git a/client/cmd-delete.cc b/client/cmd-delete.cc index d120fc9d..ffac05ee 100644 --- a/client/cmd-delete.cc +++ b/client/cmd-delete.cc @@ -87,11 +87,6 @@ namespace snapper }; ParsedOpts opts = get_opts.parse("delete", options); - if (!get_opts.has_args()) - { - cerr << _("Command 'delete' needs at least one argument.") << endl; - exit(EXIT_FAILURE); - } bool sync = false; @@ -100,6 +95,11 @@ namespace snapper if ((opt = opts.find("sync")) != opts.end()) sync = true; + if (!get_opts.has_args()) + { + SN_THROW(OptionsException(_("Command 'delete' needs at least one argument."))); + } + ProxySnapshots& snapshots = snapper->getSnapshots(); vector nums; diff --git a/client/cmd-modify.cc b/client/cmd-modify.cc index d15d4c9f..c3155630 100644 --- a/client/cmd-modify.cc +++ b/client/cmd-modify.cc @@ -59,10 +59,10 @@ namespace snapper }; ParsedOpts opts = get_opts.parse("modify", options); + if (!get_opts.has_args()) { - cerr << _("Command 'modify' needs at least one argument.") << endl; - exit(EXIT_FAILURE); + SN_THROW(OptionsException(_("Command 'modify' needs at least one argument."))); } ProxySnapshots& snapshots = snapper->getSnapshots(); diff --git a/package/snapper.changes b/package/snapper.changes index 5b30f076..0e1e56f2 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,7 +1,8 @@ ------------------------------------------------------------------- Fri Aug 28 11:06:23 CEST 2020 - aschnell@suse.com -- improved error reporting in getopt wrapper (part of bsc#1150156) +- improved error messages for wrong command line options and + arguments (bsc#1150156) ------------------------------------------------------------------- Thu Aug 27 12:04:44 CEST 2020 - aschnell@suse.com