Skip to content

Commit

Permalink
Merge pull request #7 from etienne-napoleone/feature/version
Browse files Browse the repository at this point in the history
Refactor version and cleanup
  • Loading branch information
etienne-napoleone committed Oct 7, 2018
2 parents 132b7f9 + 1eb9ddc commit 5d7e8a1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -21,4 +21,4 @@ coveralls = "^1.5"
pytest-cov = "^2.6"

[tool.poetry.scripts]
scrmbl = 'scrmbl:cli'
scrmbl = 'scrmbl.cli:cli'
6 changes: 2 additions & 4 deletions scrmbl/__init__.py
@@ -1,7 +1,5 @@
from scrmbl.main import echo
from scrmbl.cli import cli
import scrmbl.version as version

__all__ = ['echo', 'cli']
__all__ = ['echo']

__version__ = version.__version__
__version__ = '0.1.1'
47 changes: 21 additions & 26 deletions scrmbl/cli.py
Expand Up @@ -2,38 +2,33 @@

import click

from scrmbl.main import echo
import scrmbl.version
import scrmbl


@click.command()
@click.argument('text_in', default='')
@click.argument('message', default='')
@click.option('-s', '--speed', type=click.FLOAT, default=0.05,
help='Time in seconds between prints. Default: 0.05')
@click.option('-i', '--iter', 'niter', type=click.INT, default=2,
@click.option('-i', '--iterations', type=click.INT, default=2,
help='Number of iterations per character. Default: 2')
@click.option('-c', '--chars', type=click.Path(
exists=True, allow_dash=True, dir_okay=False,
), help='Set of chars to scramble.')
@click.version_option(version=scrmbl.version.__version__)
def cli(text_in: str, speed: float, niter: int, chars: str):
@click.option('-c', '--charset',
type=click.Path(exists=True, allow_dash=True, dir_okay=False),
help='Set of chars to scramble.')
@click.version_option(version=scrmbl.__version__)
def cli(message: str, speed: float, iterations: int, charset: str) -> None:
"""Scrmbl print the given message."""
if not text_in: # no text input
if sys.stdin.isatty() or chars == '-': # if no stdin or just '-c -'
raise click.UsageError('Need TEXT_IN or stdin input.')

# no text input
if not message:
# if no stdin or just '-c -'
if sys.stdin.isatty() or charset == '-':
raise click.UsageError('"MESSAGE" is empty. No argument or stdin.')
for line in sys.stdin:
text_in += line

if chars:
with click.open_file(chars) as f:
charset = f.read()
message += line
if charset:
with click.open_file(charset) as f:
charset_content = f.read()
charset_content = charset_content.replace('\n', '')
else:
charset = ''

echo(text_in.strip(), charset=charset, speed=speed, iterations=niter)


# for debugging >.\cli.py testing
# if __name__ == '__main__':
# cli()
charset_content = None
scrmbl.echo(message.strip(), charset=charset_content, speed=speed,
iterations=iterations)
7 changes: 1 addition & 6 deletions scrmbl/main.py
Expand Up @@ -15,10 +15,6 @@ def echo(message: str, charset: str = ALL_CHARS, speed: float = 0.05,
"""Scrmbl print the given message."""
if not charset:
charset = ALL_CHARS

# strip \n and \r from charset
charset = charset.replace('\n', '').replace('\r', '')

for line in message.split('\n'):
echoed = ''
for char in line:
Expand All @@ -27,8 +23,7 @@ def echo(message: str, charset: str = ALL_CHARS, speed: float = 0.05,
click.echo('\r{0}{1}'.format(echoed, ran_char), nl=False)
time.sleep(speed)
echoed += char

# this logic is so lines longer than the console wrap around
# wrap if line longer than console cols
if len(echoed) >= COLS - 1:
click.echo('\r' + echoed)
echoed = ''
Expand Down
1 change: 0 additions & 1 deletion scrmbl/version.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/test_scrmbl.py
@@ -1,9 +1,8 @@
import scrmbl
from scrmbl import __version__


def test_version():
assert __version__ == '0.1.1'
assert scrmbl.__version__ == '0.1.1'


def test_echo_single(capsys):
Expand Down

0 comments on commit 5d7e8a1

Please sign in to comment.