Skip to content

Commit

Permalink
Merge pull request openSUSE#875 from aschnell/master
Browse files Browse the repository at this point in the history
- use table for printing command line options help
  • Loading branch information
aschnell authored Feb 26, 2024
2 parents 98ca424 + 47d8d44 commit 21eded8
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 101 deletions.
44 changes: 24 additions & 20 deletions client/GlobalOptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <snapper/AppUtil.h>

#include "utils/help.h"
#include "misc.h"
#include "client/GlobalOptions.h"
#include "client/utils/text.h"
Expand All @@ -34,27 +35,30 @@ namespace snapper
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.") }
});
}


Expand Down
2 changes: 1 addition & 1 deletion client/GlobalOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace snapper
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);

Expand Down
11 changes: 7 additions & 4 deletions client/cmd-cleanup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "utils/HumanString.h"
#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "cleanup.h"
Expand All @@ -53,10 +54,12 @@ namespace snapper
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.") }
});
}


Expand Down
11 changes: 7 additions & 4 deletions client/cmd-create-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <snapper/AppUtil.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"

Expand All @@ -42,10 +43,12 @@ namespace snapper
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.") }
});
}


Expand Down
27 changes: 15 additions & 12 deletions client/cmd-create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <snapper/AppUtil.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
Expand All @@ -43,18 +44,20 @@ namespace snapper
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.") }
});
}


Expand Down
9 changes: 6 additions & 3 deletions client/cmd-delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <snapper/AppUtil.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"

Expand All @@ -42,9 +43,11 @@ namespace snapper
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.") }
});
}


Expand Down
13 changes: 8 additions & 5 deletions client/cmd-diff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <snapper/AppUtil.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
Expand All @@ -44,11 +45,13 @@ namespace snapper
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.") }
});
}


Expand Down
11 changes: 6 additions & 5 deletions client/cmd-get-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <iostream>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
Expand All @@ -44,11 +45,11 @@ namespace snapper
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.") }
});
}


Expand Down
10 changes: 6 additions & 4 deletions client/cmd-list-configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <iostream>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
Expand All @@ -44,10 +45,11 @@ namespace snapper
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.") }
});
}


Expand Down
18 changes: 9 additions & 9 deletions client/cmd-list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <snapper/BtrfsUtils.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "locker.h"
Expand All @@ -53,15 +54,14 @@ namespace snapper
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." ) }
});
}


Expand Down
19 changes: 11 additions & 8 deletions client/cmd-modify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <snapper/Filesystem.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
Expand All @@ -43,14 +44,16 @@ namespace snapper
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.") },
});
}


Expand Down
15 changes: 9 additions & 6 deletions client/cmd-rollback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <snapper/PluginsImpl.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "misc.h"
Expand All @@ -49,12 +50,14 @@ namespace snapper
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.") }
});
}


Expand Down
9 changes: 6 additions & 3 deletions client/cmd-status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <snapper/AppUtil.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "MyFiles.h"
Expand All @@ -43,9 +44,11 @@ namespace snapper
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.") }
});
}


Expand Down
9 changes: 6 additions & 3 deletions client/cmd-undochange.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <snapper/AppUtil.h>

#include "utils/text.h"
#include "utils/help.h"
#include "GlobalOptions.h"
#include "proxy.h"
#include "MyFiles.h"
Expand All @@ -43,9 +44,11 @@ namespace snapper
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.") }
});
}


Expand Down
Loading

0 comments on commit 21eded8

Please sign in to comment.