--silent option for sqlite-utils insert-files, closes #301

This commit is contained in:
Simon Willison 2021-08-02 12:12:16 -07:00
commit 60dea99ef7
3 changed files with 31 additions and 7 deletions

View file

@ -260,14 +260,21 @@ class ValueTracker:
class NullProgressBar:
def __init__(self, *args):
self.args = args
def __iter__(self):
yield from self.args[0]
def update(self, value):
pass
@contextlib.contextmanager
def progressbar(silent=False, **kwargs):
def progressbar(*args, **kwargs):
silent = kwargs.pop("silent")
if silent:
yield NullProgressBar()
yield NullProgressBar(*args)
else:
with click.progressbar(**kwargs) as bar:
with click.progressbar(*args, **kwargs) as bar:
yield bar