This allow forcing the progress mode regardless of whether fd 1 is tty or not.

Signed-off-by: Eetu Eloranta <[email protected]>
---
 src/common.h    |  7 +++++++
 src/main.c      | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/mbsync.1.in |  6 ++++++
 src/util.c      |  1 +
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/src/common.h b/src/common.h
index 38521b6..28b7833 100644
--- a/src/common.h
+++ b/src/common.h
@@ -143,6 +143,12 @@ enum {
        VERBOSE,
 };
 
+enum {
+       PROGRESS_AUTO,
+       PROGRESS_ALWAYS,
+       PROGRESS_NEVER,
+};
+
 #define options_enum(fn) \
        fn(DEBUG_MAILDIR) \
        fn(DEBUG_NET) \
@@ -175,6 +181,7 @@ DEFINE_BIT_ENUM(options_enum)
 
 // Global options
 extern int Verbosity;
+extern int ProgressMode;
 extern int DFlags;
 extern int JLimit, JCount;
 extern int UseFSync;
diff --git a/src/main.c b/src/main.c
index 8581b0c..538c03d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,6 +48,7 @@ PACKAGE " " VERSION " - mailbox synchronizer\n"
 "  -D, --debug         debugging modes (see manual)\n"
 "  -y, --dry-run               do not actually modify anything\n"
 "  -e, --ext-exit      return extended exit code\n"
+"  -p, --progress MODE select progress mode (see manual, default: auto)\n"
 "  -V, --verbose               display what is happening\n"
 "  -q, --quiet         don't display progress counters\n"
 "  -v, --version               display version\n"
@@ -163,6 +164,18 @@ countStep( void )
                exit( 100 );
 }
 
+static int
+parse_progress_mode( const char *mode )
+{
+       if (!strcmp( mode, "auto" ))
+               return PROGRESS_AUTO;
+       if (!strcmp( mode, "always" ))
+               return PROGRESS_ALWAYS;
+       if (!strcmp( mode, "never" ))
+               return PROGRESS_NEVER;
+       return -1;
+}
+
 int
 main( int argc, char **argv )
 {
@@ -244,6 +257,27 @@ main( int argc, char **argv )
                                        DFlags |= DRYRUN;
                                } else if (!strcmp( opt, "ext-exit" )) {
                                        DFlags |= EXT_EXIT;
+                               } else if (!strcmp( opt, "progress" )) {
+                                       int mode;
+
+                                       if (oind >= argc) {
+                                               error( "--progress requires an 
argument.\n" );
+                                               return 1;
+                                       }
+                                       if ((mode = parse_progress_mode( 
argv[oind++] )) < 0) {
+                                               error("Invalid progress mode 
'%s'\n",
+                                                     argv[oind - 1]);
+                                               return 1;
+                                       }
+                                       ProgressMode = mode;
+                               } else if (starts_with( opt, -1, "progress=", 
9)) {
+                                       int mode;
+
+                                       if ((mode = parse_progress_mode( opt + 
9 )) < 0) {
+                                               error( "Invalid progress mode 
'%s'\n", opt + 9 );
+                                               return 1;
+                                       }
+                                       ProgressMode = mode;
                                } else if (!strcmp( opt, "pull" )) {
                                        cops |= XOP_PULL, mvars->ops[F] |= 
XOP_HAVE_TYPE;
                                } else if (!strcmp( opt, "push" )) {
@@ -445,6 +479,21 @@ main( int argc, char **argv )
                case 'V':
                        Verbosity = VERBOSE;
                        break;
+               case 'p': {
+                       int mode;
+
+                       if (oind >= argc) {
+                               error( "-p requires an argument.\n" );
+                               return 1;
+                       }
+
+                       if ((mode = parse_progress_mode( argv[oind++] )) < 0) {
+                               error( "Invalid progress mode '%s'\n", 
argv[oind - 1] );
+                               return 1;
+                       }
+                       ProgressMode = mode;
+                       break;
+               }
                case 'D':
                        for (op = 0; *ochar; ochar++) {
                                switch (*ochar) {
@@ -543,7 +592,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 &&
+                  (ProgressMode == PROGRESS_ALWAYS ||
+                   (ProgressMode == PROGRESS_AUTO && isatty( 1 )))) {
                DFlags |= PROGRESS;
        }
 
diff --git a/src/mbsync.1.in b/src/mbsync.1.in
index 5169b31..375b5e2 100644
--- a/src/mbsync.1.in
+++ b/src/mbsync.1.in
@@ -89,6 +89,12 @@ 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, \fB--progress\fR \fImode\fR
+Set progress visibility to \fImode\fR. Allowed modes are \fIauto\fR (default),
+\fIalways\fR and \fInever\fR.  In \fIauto\fR mode, the progress is only shown
+when stdout is connected to a TTY, and not to a file or a pipe.  This can be
+overridden by setting the progress mode to \fInever\fR or \fIalways\fR.
+.TP
 \fB-V\fR, \fB--verbose\fR
 Enable \fIverbose\fR mode, which displays what is currently happening.
 .TP
diff --git a/src/util.c b/src/util.c
index 22e639f..03c00ad 100644
--- a/src/util.c
+++ b/src/util.c
@@ -15,6 +15,7 @@
 #include <sys/time.h>
 
 int Verbosity = TERSE;
+int ProgressMode = PROGRESS_AUTO;
 int DFlags;
 int JLimit, JCount;
 int UseFSync = 1;
-- 
2.55.0



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

Reply via email to