Repository: borgbackup/borg

Issue:
borg create -p does not show progress in 0.28.1
With 0.27 one used to see progress information such as current file being backed up, current raw, compressed, unduplicated size, etc.

Now, on 0.28.1 I only see two messages:

```
reading files cache
processing files
```

and nothing else.

Thanks in advance for looking into it.



Discussion:
--progress is a toggle now and if you start borg from a terminal, it is on by default.

Clear now...

but please, rethink.  Having an option that acts as a toggle on something that is selected automatically based on whether your output is a terminal makes things unnecessarily complex for scripting.  For instance: how can a script assure that progress is always off, regardless of the output being a terminal or not? It needs to first determine itself if the output is a terminal and then decide whether to use --progress or not depending on that.

I think that having --progress and -p for "unconditionally switch on progress" and "--no-progress" for "unconditionally switch off progress" would be much easier. 

@sergiocallegari usually I would agree, I also dislike magic behaviour. it is often causing troubles.

but for progress, isn't it doing now the right thing by default?
(except existing scripts where you want to remove --progress now)

Exactly... the new automatic default behavior is quite nice, but now it is difficult to reliably switch the progress display off in scripts. This is the reason for my suggestion for a --no-progress option to unconditionally switch off progress display. And if we get this, then --progress should probably be unconditional too "for simmetry".

@anarcat ^


Resolving patch:
diff --git a/borg/archiver.py b/borg/archiver.py
--- a/borg/archiver.py
+++ b/borg/archiver.py
@@ -761,6 +761,19 @@ def build_parser(self, args=None, prog=None):
         See the output of the "borg help patterns" command for more help on exclude patterns.
         """)
 
+        class ToggleAction(argparse.Action):
+            """argparse action to handle "toggle" flags easily
+
+            toggle flags are in the form of ``--foo``, ``--no-foo``.
+
+            the ``--no-foo`` argument still needs to be passed to the
+            ``add_argument()`` call, but it simplifies the ``--no``
+            detection.
+            """
+            def __call__(self, parser, ns, values, option):
+                """set the given flag to true unless ``--no`` is passed"""
+                setattr(ns, self.dest, option.startswith('--no-'))
+
         subparser = subparsers.add_parser('create', parents=[common_parser],
                                           description=self.do_create.__doc__,
                                           epilog=create_epilog,
@@ -769,8 +782,9 @@ def build_parser(self, args=None, prog=None):
         subparser.add_argument('-s', '--stats', dest='stats',
                                action='store_true', default=False,
                                help='print statistics for the created archive')
-        subparser.add_argument('-p', '--progress', dest='progress', const=not sys.stderr.isatty(),
-                               action='store_const', default=sys.stdin.isatty(),
+        subparser.add_argument('-p', '--progress', '--no-progress',
+                               dest='progress', default=sys.stdin.isatty(),
+                               action=ToggleAction, nargs=0,
                                help="""toggle progress display while creating the archive, showing Original,
                                Compressed and Deduplicated sizes, followed by the Number of files seen
                                and the path being processed, default: %(default)s""")


Test patch: