Shell.cc Shell.h \
CmdBtrfs.cc CmdBtrfs.h \
CmdLs.cc CmdLs.h \
- JsonFile.cc JsonFile.h
+ JsonFile.cc JsonFile.h \
+ utils.cc utils.h
snbk_LDADD = \
../../snapper/libsnapper.la \
#include "BackupConfig.h"
#include "GlobalOptions.h"
#include "TheBigThing.h"
+#include "utils.h"
namespace snapper
command_delete(const GlobalOptions& global_options, GetOpts& get_opts, BackupConfigs& backup_configs,
ProxySnappers* snappers)
{
- static const regex num_regex("[0-9]+", regex::extended);
-
ParsedOpts opts = get_opts.parse("delete", GetOpts::no_options);
- vector<unsigned int> nums;
-
- while (get_opts.has_args())
- {
- string arg = get_opts.pop_arg();
-
- if (!regex_match(arg, num_regex))
- SN_THROW(Exception(_("Failed to parse number.")));
-
- nums.push_back(stoi(arg));
- }
+ vector<unsigned int> nums = parse_nums(get_opts);
unsigned int errors = 0;
#include "BackupConfig.h"
#include "GlobalOptions.h"
#include "TheBigThing.h"
-#include "cmd.h"
+#include "utils.h"
namespace snapper
command_restore(const GlobalOptions& global_options, GetOpts& get_opts,
BackupConfigs& backup_configs, ProxySnappers* snappers)
{
- static const regex num_regex("[0-9]+", regex::extended);
-
ParsedOpts opts = get_opts.parse("restore", GetOpts::no_options);
- vector<unsigned int> nums;
-
- while (get_opts.has_args())
- {
- string arg = get_opts.pop_arg();
-
- if (!regex_match(arg, num_regex))
- SN_THROW(Exception(_("Failed to parse number.")));
-
- nums.push_back(stoi(arg));
- }
-
if (backup_configs.size() != 1)
{
SN_THROW(OptionsException(_("A backup-config must be specified to run this "
"command.")));
}
+ vector<unsigned int> nums = parse_nums(get_opts);
+
unsigned int errors = 0;
for (const BackupConfig& backup_config : backup_configs)
#include "BackupConfig.h"
#include "GlobalOptions.h"
#include "TheBigThing.h"
-#include "cmd.h"
+#include "utils.h"
namespace snapper
command_transfer(const GlobalOptions& global_options, GetOpts& get_opts, BackupConfigs& backup_configs,
ProxySnappers* snappers)
{
- static const regex num_regex("[0-9]+", regex::extended);
-
ParsedOpts opts = get_opts.parse("transfer", GetOpts::no_options);
- vector<unsigned int> nums;
-
- while (get_opts.has_args())
- {
- string arg = get_opts.pop_arg();
-
- if (!regex_match(arg, num_regex))
- SN_THROW(Exception(_("Failed to parse number.")));
-
- nums.push_back(stoi(arg));
- }
+ vector<unsigned int> nums = parse_nums(get_opts);
unsigned int errors = 0;
--- /dev/null
+/*
+ * Copyright (c) [2024-2025] SUSE LLC
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include <regex>
+
+#include "../utils/GetOpts.h"
+#include "../utils/text.h"
+
+
+namespace snapper
+{
+
+ vector<unsigned int>
+ parse_nums(GetOpts& get_opts)
+ {
+ static const regex num_regex("[0-9]+", regex::extended);
+
+ vector<unsigned int> nums;
+
+ while (get_opts.has_args())
+ {
+ string arg = get_opts.pop_arg();
+
+ if (!regex_match(arg, num_regex))
+ SN_THROW(Exception(_("Failed to parse number.")));
+
+ nums.push_back(stoi(arg));
+ }
+
+ return nums;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) [2024-2025] SUSE LLC
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include "../utils/GetOpts.h"
+
+
+namespace snapper
+{
+
+ vector<unsigned int>
+ parse_nums(GetOpts& get_opts);
+
+}