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());
#include <iostream>
+#include <snapper/AppUtil.h>
+
#include "utils/text.h"
#include "GlobalOptions.h"
#include "proxy.h"
};
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 };
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));
}
}
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)
};
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;
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<ProxySnapshots::iterator> nums;
};
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();
-------------------------------------------------------------------
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