Skip to content

Commit

Permalink
cli: add --null
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Sep 12, 2020
1 parent 4a22f27 commit 4a3d9b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ Extra CLI Options
* update_to : bool, optional
If true, will treat input as total elapsed iterations,
i.e. numbers to assign to ``self.n``.
* null : bool, optional
If true, will discard input (no stdout).
* manpath : str, optional
Directory in which to install tqdm man pages.
* comppath : str, optional
Expand Down
15 changes: 12 additions & 3 deletions tqdm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""
from .std import tqdm, TqdmTypeError, TqdmKeyError
from ._version import __version__ # NOQA
import sys
import re
import logging
import re
import sys
__all__ = ["main"]
log = logging.getLogger(__name__)

Expand Down Expand Up @@ -148,6 +148,8 @@ def posix_pipe(fin, fout, delim=b'\\n', buf_size=256,
update_to : bool, optional
If true, will treat input as total elapsed iterations,
i.e. numbers to assign to `self.n`.
null : bool, optional
If true, will discard input (no stdout).
manpath : str, optional
Directory in which to install tqdm man pages.
comppath : str, optional
Expand Down Expand Up @@ -248,8 +250,15 @@ def main(fp=sys.stderr, argv=None):
tee = tqdm_args.pop('tee', False)
manpath = tqdm_args.pop('manpath', None)
comppath = tqdm_args.pop('comppath', None)
if tqdm_args.pop('null', False):
class stdout(object):
@staticmethod
def write(_):
pass
else:
stdout = sys.stdout
stdout = getattr(stdout, 'buffer', stdout)
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
stdout = getattr(sys.stdout, 'buffer', sys.stdout)
if manpath or comppath:
from os import path
from shutil import copyfile
Expand Down
2 changes: 1 addition & 1 deletion tqdm/completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _tqdm(){
COMPREPLY=($(compgen -W 'CRITICAL FATAL ERROR WARN WARNING INFO DEBUG NOTSET' -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W '--ascii --bar_format --buf_size --bytes --comppath --delim --desc --disable --dynamic_ncols --help --initial --leave --lock_args --log --manpath --maxinterval --mininterval --miniters --ncols --nrows --position --postfix --smoothing --tee --total --unit --unit_divisor --unit_scale --update --update_to --version --write_bytes -h -v' -- ${cur}))
COMPREPLY=($(compgen -W '--ascii --bar_format --buf_size --bytes --comppath --delim --desc --disable --dynamic_ncols --help --initial --leave --lock_args --log --manpath --maxinterval --mininterval --miniters --ncols --nrows --null --position --postfix --smoothing --tee --total --unit --unit_divisor --unit_scale --update --update_to --version --write_bytes -h -v' -- ${cur}))
;;
esac
}
Expand Down
6 changes: 6 additions & 0 deletions tqdm/tqdm.1
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ numbers to assign to \f[C]self.n\f[].
.RS
.RE
.TP
.B \-\-null=\f[I]null\f[]
bool, optional.
If true, will discard input (no stdout).
.RS
.RE
.TP
.B \-\-manpath=\f[I]manpath\f[]
str, optional.
Directory in which to install tqdm man pages.
Expand Down

0 comments on commit 4a3d9b1

Please sign in to comment.