Skip to content

Commit

Permalink
cmdline: simplify meaning of --progress
Browse files Browse the repository at this point in the history
The behavior of --progress could be surprising, especially when combined
with --replay. Simplify its meaning and make sure the docs describe it
accurately.

Fixes sahib#581
  • Loading branch information
cebtenzzre committed Aug 5, 2022
1 parent bdb591f commit 9908edd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 66 deletions.
7 changes: 2 additions & 5 deletions docs/rmlint.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ General Options
$ rmlint -T "df,dd" # Only search for duplicate files and directories
$ rmlint -T "all -df -dd" # Search for all lint except duplicate files and dirs.

:``-o --output=spec`` / ``-O --add-output=spec`` (**default\:** *-o sh\:rmlint.sh -o pretty\:stdout -o summary\:stdout -o json\:rmlint.json*):
:``-o --output=spec`` / ``-O --add-output=spec`` (**default\:** *-o sh\:rmlint.sh -o pretty -o summary -o json\:rmlint.json*):

Configure the way ``rmlint`` outputs its results. A ``spec`` is in the form
``format:file`` or just ``format``. A ``file`` might either be an
Expand Down Expand Up @@ -207,10 +207,7 @@ General Options

Show a progressbar with sane defaults.

Convenience shortcut for ``-o progressbar -o summary -o sh:rmlint.sh -o json:rmlint.json -VV``.

NOTE: This flag clears all previous outputs. If you want additional
outputs, specify them after this flag using ``-O``.
Turns off the default ``-o pretty`` and enables ``-O progressbar -VV``.

:``-D --merge-directories`` (**default\:** *disabled*):

Expand Down
44 changes: 9 additions & 35 deletions lib/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,23 +732,15 @@ static gboolean rm_cmd_parse_clamp_top(_UNUSED const char *option_name, const gc
return (error && *error == NULL);
}

static gboolean rm_cmd_parse_progress(_UNUSED const char *option_name,
_UNUSED const gchar *value, RmSession *session,
_UNUSED GError **error) {
rm_fmt_remove_by_name(session->formats, "pretty");

rm_fmt_add(session->formats, "progressbar", "stdout");
rm_fmt_add(session->formats, "summary", "stdout");

session->cfg->progress_enabled = true;

return true;
}

static void rm_cmd_set_default_outputs(RmSession *session) {
rm_fmt_add(session->formats, "pretty", "stdout");
rm_fmt_add(session->formats, "summary", "stdout");

if(session->cfg->progress_enabled) {
rm_fmt_add(session->formats, "progressbar", "stdout");
} else {
rm_fmt_add(session->formats, "pretty", "stdout");
}

if(session->cfg->replay) {
rm_fmt_add(session->formats, "sh", "rmlint.replay.sh");
rm_fmt_add(session->formats, "json", "rmlint.replay.json");
Expand All @@ -758,14 +750,6 @@ static void rm_cmd_set_default_outputs(RmSession *session) {
}
}

static gboolean rm_cmd_parse_no_progress(_UNUSED const char *option_name,
_UNUSED const gchar *value, RmSession *session,
_UNUSED GError **error) {
rm_fmt_clear(session->formats);
rm_cmd_set_default_outputs(session);
return true;
}

static gboolean rm_cmd_parse_paranoid(_UNUSED const char *option_name,
_UNUSED const gchar *count, RmSession *session,
_UNUSED GError **error) {
Expand Down Expand Up @@ -1064,7 +1048,7 @@ static bool rm_cmd_set_outputs(RmSession *session, GError **error) {
g_set_error(error, RM_ERROR_QUARK, 0,
_("Specifying both -o and -O is not allowed"));
return false;
} else if(session->output_cnt[0] < 0 && session->cfg->progress_enabled == false) {
} else if(session->output_cnt[0] < 0) {
rm_cmd_set_default_outputs(session);
}

Expand Down Expand Up @@ -1126,13 +1110,13 @@ bool rm_cmd_parse_args(int argc, char **argv, RmSession *session) {
{"xattr" , 'C' , EMPTY , G_OPTION_ARG_CALLBACK , FUNC(xattr) , _("Enable xattr based caching") , ""} ,

/* Non-trivial switches */
{"progress" , 'g' , EMPTY , G_OPTION_ARG_CALLBACK , FUNC(progress) , _("Enable progressbar") , NULL} ,
{"loud" , 'v' , EMPTY , G_OPTION_ARG_CALLBACK , rm_logger_louder , _("Be more verbose (-vv for much more)") , NULL} ,
{"quiet" , 'V' , EMPTY , G_OPTION_ARG_CALLBACK , rm_logger_quieter , _("Be less verbose (-VV for much less)") , NULL} ,
{"replay" , 'Y' , 0 , G_OPTION_ARG_CALLBACK , FUNC(replay) , _("Re-output a json file") , "path/to/rmlint.json"} ,
{"equal" , 0 , EMPTY , G_OPTION_ARG_CALLBACK , FUNC(equal) , _("Test for equality of PATHS") , "PATHS"} ,

/* Trivial boolean options */
{"progress" , 'g' , 0 , G_OPTION_ARG_NONE , &cfg->progress_enabled , _("Enable progressbar") , NULL} ,
{"no-with-color" , 'W' , DISABLE , G_OPTION_ARG_NONE , &cfg->with_color , _("Be not that colorful") , NULL} ,
{"hidden" , 'r' , EMPTY , G_OPTION_ARG_CALLBACK , FUNC(hidden) , _("Find hidden files") , NULL} ,
{"followlinks" , 'f' , EMPTY , G_OPTION_ARG_CALLBACK , FUNC(follow_symlinks) , _("Follow symlinks") , NULL} ,
Expand Down Expand Up @@ -1186,7 +1170,7 @@ bool rm_cmd_parse_args(int argc, char **argv, RmSession *session) {
{"no-match-extension" , 'E' , DISABLE | HIDDEN , G_OPTION_ARG_NONE , &cfg->match_with_extension , "Disable --match-extension" , NULL} ,
{"no-match-extension" , 'E' , DISABLE | HIDDEN , G_OPTION_ARG_NONE , &cfg->match_with_extension , "Disable --match-extension" , NULL} ,
{"no-match-without-extension" , 'I' , DISABLE | HIDDEN , G_OPTION_ARG_NONE , &cfg->match_without_extension , "Disable --match-without-extension" , NULL} ,
{"no-progress" , 'G' , EMPTY | HIDDEN , G_OPTION_ARG_CALLBACK , FUNC(no_progress) , "Disable progressbar" , NULL} ,
{"no-progress" , 'G' , DISABLE | HIDDEN , G_OPTION_ARG_NONE , &cfg->progress_enabled , "Disable progressbar" , NULL} ,
{"no-xattr-read" , 0 , DISABLE | HIDDEN , G_OPTION_ARG_NONE , &cfg->read_cksum_from_xattr , "Disable --xattr-read" , NULL} ,
{"no-xattr-write" , 0 , DISABLE | HIDDEN , G_OPTION_ARG_NONE , &cfg->write_cksum_to_xattr , "Disable --xattr-write" , NULL} ,
{"no-partial-hidden" , 0 , EMPTY | HIDDEN , G_OPTION_ARG_CALLBACK , FUNC(no_partial_hidden) , "Invert --partial-hidden" , NULL} ,
Expand Down Expand Up @@ -1322,16 +1306,6 @@ bool rm_cmd_parse_args(int argc, char **argv, RmSession *session) {
_("will also disable --merge-directories and trigger this warning."));
}

if(cfg->progress_enabled) {
if(!rm_fmt_has_formatter(session->formats, "sh")) {
rm_fmt_add(session->formats, "sh", "rmlint.sh");
}

if(!rm_fmt_has_formatter(session->formats, "json")) {
rm_fmt_add(session->formats, "json", "rmlint.json");
}
}

/* Overwrite color if we do not print to a terminal directly */
if(cfg->with_color) {
cfg->with_stdout_color = isatty(fileno(stdout));
Expand Down
21 changes: 0 additions & 21 deletions lib/formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,6 @@ bool rm_fmt_is_valid_key(RmFmtTable *self, const char *formatter, const char *ke
return false;
}

void rm_fmt_remove_by_name(RmFmtTable *self, char *name) {
GQueue deleted_iters = G_QUEUE_INIT;
for(GList *iter = self->handler_order->head; iter; iter = iter->next) {
RmFmtHandler *handler = iter->data;
if(!g_str_equal(handler->name, name)) {
continue;
}

g_hash_table_remove(self->handler_to_file, handler);
g_hash_table_remove(self->path_to_handler, handler->path);
g_queue_push_tail(&deleted_iters, iter);
}

for(GList *iter = deleted_iters.head; iter; iter = iter->next) {
g_queue_delete_link(self->handler_order, iter);
}

// Since we removed all handlers
g_hash_table_remove(self->handler_set, name);
}

// NOTE: This is the same as g_date_time_format_iso8601.
// It is only copied here because it is only available since
// GLib 2.62. Remove this in a few years (written as of end 2019)
Expand Down
5 changes: 0 additions & 5 deletions lib/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ bool rm_fmt_is_stream(RmFmtTable *self, RmFmtHandler *handler);
*/
bool rm_fmt_has_formatter(RmFmtTable *self, const char *name);

/**
* @brief Remove all registered formatters with `name`.
*/
void rm_fmt_remove_by_name(RmFmtTable *self, char *name);

/**
* You can use this template for implementing new RmFmtHandlers.
* All callbacks are not required to be implemented, leave them to NULL if
Expand Down

0 comments on commit 9908edd

Please sign in to comment.