#include <snapper/AppUtil.h>
+#include "utils/help.h"
#include "misc.h"
#include "client/GlobalOptions.h"
#include "client/utils/text.h"
using namespace std;
- string
- GlobalOptions::help_text()
+ void
+ GlobalOptions::help_global_options()
{
- return string(_(" Global options:")) + '\n'
- + _("\t--quiet, -q\t\t\tSuppress normal output.") + '\n'
- + _("\t--verbose, -v\t\t\tIncrease verbosity.") + '\n'
- + _("\t--debug\t\t\t\tTurn on debugging.") + '\n'
- + _("\t--utc\t\t\t\tDisplay dates and times in UTC.") + '\n'
- + _("\t--iso\t\t\t\tDisplay dates and times in ISO format.") + '\n'
- + _("\t--table-style, -t <style>\tTable style (integer).") + '\n'
- + _("\t--abbreviate\t\t\tAllow to abbreviate table columns.") + '\n'
- + _("\t--machine-readable <format>\tSet a machine-readable output format (csv, json).") + '\n'
- + _("\t--csvout\t\t\tSet CSV output format.") + '\n'
- + _("\t--jsonout\t\t\tSet JSON output format.") + '\n'
- + _("\t--separator <separator>\t\tCharacter separator for CSV output format.") + '\n'
- + _("\t--no-headers\t\t\tNo headers for CSV output format.") + '\n'
- + _("\t--config, -c <name>\t\tSet name of config to use.") + '\n'
- + _("\t--no-dbus\t\t\tOperate without DBus.") + '\n'
- + _("\t--root, -r <path>\t\tOperate on target root (works only without DBus).") + '\n'
- + _("\t--ambit, -a ambit\t\tOperate in the specified ambit.") + '\n'
- + _("\t--version\t\t\tPrint version and exit.") + '\n';
+ cout << _(" Global options:") << '\n';
+
+ print_options({
+ { _("--quiet, -q"), _("Suppress normal output.") },
+ { _("--verbose, -v"), _("Increase verbosity.") },
+ { _("--debug"), _("Turn on debugging.") },
+ { _("--utc"), _("Display dates and times in UTC.") },
+ { _("--iso"), _("Display dates and times in ISO format.") },
+ { _("--table-style, -t <style>"), _("Table style (integer).") },
+ { _("--abbreviate"), _("Allow to abbreviate table columns.") },
+ { _("--machine-readable <format>"), _("Set a machine-readable output format (csv, json).") },
+ { _("--csvout"), _("Set CSV output format.") },
+ { _("--jsonout"), _("Set JSON output format.") },
+ { _("--separator <separator>"), _("Character separator for CSV output format.") },
+ { _("--no-headers"), _("No headers for CSV output format.") },
+ { _("--config, -c <name>"), _("Set name of config to use.") },
+ { _("--no-dbus"), _("Operate without DBus.") },
+ { _("--root, -r <path>"), _("Operate on target root (works only without DBus).") },
+ { _("--ambit, -a <ambit>"), _("Operate in the specified ambit.") },
+ { _("--version"), _("Print version and exit.") }
+ });
}
enum class OutputFormat { TABLE, CSV, JSON };
enum class Ambit { AUTO, CLASSIC, TRANSACTIONAL };
- static string help_text();
+ static void help_global_options();
GlobalOptions(GetOpts& get_opts);
#include "utils/HumanString.h"
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "cleanup.h"
cout << _(" Cleanup snapshots:") << '\n'
<< _("\tsnapper cleanup <cleanup-algorithm>") << '\n'
<< '\n'
- << _(" Options for 'cleanup' command:") << '\n'
- << _("\t--path <path>\t\t\tCleanup all configs affecting path.") << '\n'
- << _("\t--free-space <space>\t\tTry to make space available.") << '\n'
- << endl;
+ << _(" Options for 'cleanup' command:") << '\n';
+
+ print_options({
+ { _("--path <path>"), _("Cleanup all configs affecting path.") },
+ { _("--free-space <space>"), _("Try to make space available.") }
+ });
}
#include <snapper/AppUtil.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
cout << _(" Create config:") << '\n'
<< _("\tsnapper create-config <subvolume>") << '\n'
<< '\n'
- << _(" Options for 'create-config' command:") << '\n'
- << _("\t--fstype, -f <fstype>\t\tManually set filesystem type.") << '\n'
- << _("\t--template, -t <name>\t\tName of config template to use.") << '\n'
- << endl;
+ << _(" Options for 'create-config' command:") << '\n';
+
+ print_options({
+ { _("--fstype, -f <fstype>"), _("Manually set filesystem type.") },
+ { _("--template, -t <name>"), _("Name of config template to use.") }
+ });
}
#include <snapper/AppUtil.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
cout << _(" Create snapshot:") << '\n'
<< _("\tsnapper create") << '\n'
<< '\n'
- << _(" Options for 'create' command:") << '\n'
- << _("\t--type, -t <type>\t\tType for snapshot.") << '\n'
- << _("\t--pre-number <number>\t\tNumber of corresponding pre snapshot.") << '\n'
- << _("\t--print-number, -p\t\tPrint number of created snapshot.") << '\n'
- << _("\t--description, -d <description>\tDescription for snapshot.") << '\n'
- << _("\t--cleanup-algorithm, -c <algo>\tCleanup algorithm for snapshot.") << '\n'
- << _("\t--userdata, -u <userdata>\tUserdata for snapshot.") << '\n'
- << _("\t--command <command>\t\tRun command and create pre and post snapshots.") << endl
- << _("\t--read-only\t\t\tCreate read-only snapshot.") << '\n'
- << _("\t--read-write\t\t\tCreate read-write snapshot.") << '\n'
- << _("\t--from <number>\t\t\tCreate a snapshot from the specified snapshot.") << '\n'
- << endl;
+ << _(" Options for 'create' command:") << '\n';
+
+ print_options({
+ { _("--type, -t <type>"), _("Type for snapshot.") },
+ { _("--pre-number <number>"), _("Number of corresponding pre snapshot.") },
+ { _("--print-number, -p"), _("Print number of created snapshot.") },
+ { _("--description, -d <description>"), _("Description for snapshot.") },
+ { _("--cleanup-algorithm, -c <algo>"), _("Cleanup algorithm for snapshot.") },
+ { _("--userdata, -u <userdata>"), _("Userdata for snapshot.") },
+ { _("--command <command>"), _("Run command and create pre and post snapshots.")},
+ { _("--read-only"), _("Create read-only snapshot.") },
+ { _("--read-write"), _("Create read-write snapshot.") },
+ { _("--from <number>"), _("Create a snapshot from the specified snapshot.") }
+ });
}
#include <snapper/AppUtil.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
cout << _(" Delete snapshot:") << '\n'
<< _("\tsnapper delete <number>") << '\n'
<< '\n'
- << _(" Options for 'delete' command:") << '\n'
- << _("\t--sync, -s\t\t\tSync after deletion.") << '\n'
- << endl;
+ << _(" Options for 'delete' command:") << '\n';
+
+ print_options({
+ { _("--sync, -s"), _("Sync after deletion.") }
+ });
}
#include <snapper/AppUtil.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
cout << _(" Comparing snapshots:") << '\n'
<< _("\tsnapper diff <number1>..<number2> [files]") << '\n'
<< '\n'
- << _(" Options for 'diff' command:") << '\n'
- << _("\t--input, -i <file>\t\tRead files to diff from file.") << '\n'
- << _("\t--diff-cmd <command>\t\tCommand used for comparing files.") << '\n'
- << _("\t--extensions, -x <options>\tExtra options passed to the diff command.") << '\n'
- << endl;
+ << _(" Options for 'diff' command:") << '\n';
+
+ print_options({
+ { _("--input, -i <file>"), _("Read files to diff from file.") },
+ { _("--diff-cmd <command>"), _("Command used for comparing files.") },
+ { _("--extensions, -x <options>"), _("Extra options passed to the diff command.") }
+ });
}
#include <iostream>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
cout << _(" Get config:") << '\n'
<< _("\tsnapper get-config") << '\n'
<< '\n'
- << _(" Options for 'get-config' command:") << '\n'
- << _("\t--columns <columns>\t\tColumns to show separated by comma.\n"
- "\t\t\t\t\tPossible columns: key, value.\n"
- "\t\t\t\t\tColumns are not selected when JSON format is used.") << '\n'
- << endl;
+ << _(" Options for 'get-config' command:") << '\n';
+
+ print_options({
+ { _("--columns <columns>"), _("Columns to show separated by comma.") }
+ });
}
#include <iostream>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
cout << _(" List configs:") << '\n'
<< _("\tsnapper list-configs") << '\n'
<< '\n'
- << _(" Options for 'list-configs' command:\n"
- "\t--columns <columns>\t\tColumns to show separated by comma.\n"
- "\t\t\t\t\tPossible columns: config, subvolume.\n")
- << endl;
+ << _(" Options for 'list-configs' command:") << '\n';
+
+ print_options({
+ { _("--columns <columns>"), _("Columns to show separated by comma.") }
+ });
}
#include <snapper/BtrfsUtils.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "locker.h"
cout << _(" List snapshots:") << '\n'
<< _("\tsnapper list") << '\n'
<< '\n'
- << _(" Options for 'list' command:") << '\n'
- << _("\t--type, -t <type>\t\tType of snapshots to list.") << '\n'
- << _("\t--disable-used-space\t\tDisable showing used space.") << '\n'
- << _("\t--all-configs, -a\t\tList snapshots from all accessible configs.") << '\n'
- << _("\t--columns <columns>\t\tColumns to show separated by comma.\n"
- "\t\t\t\t\tPossible columns: config, subvolume, number, default, active,\n"
- "\t\t\t\t\ttype, date, user, used-space, cleanup, description, userdata,\n"
- "\t\t\t\t\tpre-number, post-number, post-date, read-only.") << '\n'
- << endl;
+ << _(" Options for 'list' command:") << '\n';
+
+ print_options({
+ { _("--type, -t <type>"), _("Type of snapshots to list.") },
+ { _("--disable-used-space"), _("Disable showing used space.") },
+ { _("--all-configs, -a"), _("List snapshots from all accessible configs.") },
+ { _("--columns <columns>"), _("Columns to show separated by comma." ) }
+ });
}
#include <snapper/Filesystem.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
cout << _(" Modify snapshot:") << '\n'
<< _("\tsnapper modify <number>") << '\n'
<< '\n'
- << _(" Options for 'modify' command:") << '\n'
- << _("\t--description, -d <description>\tDescription for snapshot.") << '\n'
- << _("\t--cleanup-algorithm, -c <algo>\tCleanup algorithm for snapshot.") << '\n'
- << _("\t--userdata, -u <userdata>\tUserdata for snapshot.") << '\n'
- << _("\t--read-only\t\t\tSet snapshot read-only.") << '\n'
- << _("\t--read-write\t\t\tSet snapshot read-write.") << '\n'
- << _("\t--default\t\t\tSet snapshot as default snapshot.") << '\n'
- << endl;
+ << _(" Options for 'modify' command:") << '\n';
+
+ print_options({
+ { _("--description, -d <description>"), _("Description for snapshot.") },
+ { _("--cleanup-algorithm, -c <algo>"), _("Cleanup algorithm for snapshot.") },
+ { _("--userdata, -u <userdata>"), _("Userdata for snapshot.") },
+ { _("--read-only"), _("Set snapshot read-only.") },
+ { _("--read-write"), _("Set snapshot read-write.") },
+ { _("--default"), _("Set snapshot as default snapshot.") },
+ });
}
#include <snapper/PluginsImpl.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
cout << _(" Rollback:") << '\n'
<< _("\tsnapper rollback [number]") << '\n'
<< '\n'
- << _(" Options for 'rollback' command:") << '\n'
- << _("\t--print-number, -p\t\tPrint number of second created snapshot.") << '\n'
- << _("\t--description, -d <description>\tDescription for snapshots.") << '\n'
- << _("\t--cleanup-algorithm, -c <algo>\tCleanup algorithm for snapshots.") << '\n'
- << _("\t--userdata, -u <userdata>\tUserdata for snapshots.") << '\n'
- << endl;
+ << _(" Options for 'rollback' command:") << '\n';
+
+ print_options({
+ { _("--print-number, -p"), _("Print number of second created snapshot.") },
+ { _("--description, -d <description>"), _("Description for snapshots.") },
+ { _("--cleanup-algorithm, -c <algo>"), _("Cleanup algorithm for snapshots.") },
+ { _("--userdata, -u <userdata>"), _("Userdata for snapshots.") }
+ });
}
#include <snapper/AppUtil.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "MyFiles.h"
cout << _(" Comparing snapshots:") << '\n'
<< _("\tsnapper status <number1>..<number2>") << '\n'
<< '\n'
- << _(" Options for 'status' command:") << '\n'
- << _("\t--output, -o <file>\t\tSave status to file.") << '\n'
- << endl;
+ << _(" Options for 'status' command:") << '\n';
+
+ print_options({
+ { _("--output, -o <file>"), _("Save status to file.") }
+ });
}
#include <snapper/AppUtil.h>
#include "utils/text.h"
+#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "MyFiles.h"
cout << _(" Undo changes:") << '\n'
<< _("\tsnapper undochange <number1>..<number2> [files]") << '\n'
<< '\n'
- << _(" Options for 'undochange' command:") << '\n'
- << _("\t--input, -i <file>\t\tRead files for which to undo changes from file.") << '\n'
- << endl;
+ << _(" Options for 'undochange' command:") << '\n';
+
+ print_options({
+ { _("--input, -i <file>"), _("Read files for which to undo changes from file.") }
+ });
}
cout << _("usage: snapper [--global-options] <command> [--command-options] [command-arguments]") << '\n'
<< endl;
- cout << GlobalOptions::help_text() << endl;
+ GlobalOptions::help_global_options();
for (const Cmd& cmd : cmds)
(*cmd.help_func)();
noinst_LTLIBRARIES = libutils.la
-libutils_la_SOURCES = \
- Table.cc Table.h \
- text.cc text.h \
- console.cc console.h \
- equal-date.cc equal-date.h \
- GetOpts.cc GetOpts.h \
- Range.cc Range.h \
- HumanString.cc HumanString.h \
- Limit.cc Limit.h \
- TableFormatter.cc TableFormatter.h \
- CsvFormatter.cc CsvFormatter.h \
- JsonFormatter.cc JsonFormatter.h
+libutils_la_SOURCES = \
+ Table.cc Table.h \
+ text.cc text.h \
+ help.cc help.h \
+ console.cc console.h \
+ equal-date.cc equal-date.h \
+ GetOpts.cc GetOpts.h \
+ Range.cc Range.h \
+ HumanString.cc HumanString.h \
+ Limit.cc Limit.h \
+ TableFormatter.cc TableFormatter.h \
+ CsvFormatter.cc CsvFormatter.h \
+ JsonFormatter.cc JsonFormatter.h
libutils_la_LIBADD = ../../snapper/libsnapper.la -ltinfo
-
--- /dev/null
+/*
+ * Copyright (c) 2024 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 <iostream>
+
+#include "help.h"
+#include "Table.h"
+#include "text.h"
+
+
+namespace snapper
+{
+
+ void
+ print_options(std::initializer_list<std::initializer_list<string>> init)
+ {
+ Table table({ Cell(_("Name"), Id::NAME), Cell(_("Description"), Id::DESCRIPTION) });
+ table.set_show_header(false);
+ table.set_show_grid(false);
+ table.set_global_indent(8);
+ table.set_min_width(Id::NAME, 28);
+
+ for (const std::initializer_list<string>& row_init : init)
+ table.add(Table::Row(table, row_init));
+
+ cout << table << '\n';
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2024 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.
+ */
+
+
+#ifndef SNAPPER_HELP_H
+#define SNAPPER_HELP_H
+
+
+#include <initializer_list>
+#include <string>
+
+
+namespace snapper
+{
+
+ using namespace std;
+
+
+ void
+ print_options(std::initializer_list<std::initializer_list<string>> init);
+
+}
+
+
+#endif