This allows forcing progress mode regardless of whether fd 1 is a TTY.

Signed-off-by: Eetu Eloranta <[email protected]>
---
 src/main.c      | 22 +++++++++++++++++++++-
 src/mbsync.1.in |  4 ++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index 8581b0c..ed1f428 100644
--- a/src/main.c
+++ b/src/main.c
@@ -49,6 +49,8 @@ PACKAGE " " VERSION " - mailbox synchronizer\n"
 "  -y, --dry-run               do not actually modify anything\n"
 "  -e, --ext-exit      return extended exit code\n"
 "  -V, --verbose               display what is happening\n"
+"  -p, --progress      always show progress\n"
+"  -pn, --no-progress  never show progress\n"
 "  -q, --quiet         don't display progress counters\n"
 "  -v, --version               display version\n"
 "  -h, --help          display this help message\n"
@@ -169,6 +171,7 @@ main( int argc, char **argv )
        core_vars_t mvars[1];
        char *config = NULL, *opt, *ochar;
        int oind, cops = 0, op, ms_warn = 0, renew_warn = 0, delete_warn = 0;
+       int progress_mode = -1;
 
        tzset();
        init_timers();
@@ -215,6 +218,10 @@ main( int argc, char **argv )
                                } else if (!strcmp( opt, "quiet" )) {
                                        if (Verbosity > VERYQUIET)
                                                Verbosity--;
+                               } else if (!strcmp( opt, "progress" )) {
+                                       progress_mode = 1;
+                               } else if (!strcmp( opt, "no-progress" )) {
+                                       progress_mode = 0;
                                } else if (!strcmp( opt, "verbose" )) {
                                        Verbosity = VERBOSE;
                                } else if (starts_with( opt, -1, "debug", 5 )) {
@@ -442,6 +449,17 @@ main( int argc, char **argv )
                        if (Verbosity > VERYQUIET)
                                Verbosity--;
                        break;
+               case 'p':
+                       if (*ochar == 'n' ) {
+                               progress_mode = 0;
+                               ochar++;
+                       } else if (!*ochar) {
+                               progress_mode = 1;
+                       } else {
+                               error( "Unknown -p flag '%c'\n", *ochar );
+                               return 1;
+                       };
+                       break;
                case 'V':
                        Verbosity = VERBOSE;
                        break;
@@ -543,7 +561,9 @@ main( int argc, char **argv )
                for (op = 1; op < argc; op++)
                        printf( " '%s'", argv[op] );
                puts( "" );
-       } else if (Verbosity >= TERSE && isatty( 1 )) {
+       } else if (Verbosity >= TERSE &&
+                  (progress_mode > 0 ||
+                   (progress_mode < 0 && isatty( 1 )))) {
                DFlags |= PROGRESS;
        }
 
diff --git a/src/mbsync.1.in b/src/mbsync.1.in
index 5169b31..fd57bff 100644
--- a/src/mbsync.1.in
+++ b/src/mbsync.1.in
@@ -89,6 +89,10 @@ pushed and pulled.
 An error may be reported at the same time, so the code may be for example
 65 if some changes were successfully pulled, while others failed.
 .TP
+\fB-p\fR[\fBn\fR], \fB--\fR[\fBno-\fR]\fBprogress\fR
+Set progress visibility. By default the progress is only shown when stdout is
+connected to a TTY, and not to a file or a pipe.
+.TP
 \fB-V\fR, \fB--verbose\fR
 Enable \fIverbose\fR mode, which displays what is currently happening.
 .TP
-- 
2.55.0



_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to