more housekeeping

main
mat ess 2023-08-13 17:50:40 -04:00
parent 89876df526
commit 774e97260a
3 changed files with 18 additions and 13 deletions

View File

@ -1,3 +1,5 @@
set shell := ["fish", "-c"]
build: build:
hatch build hatch build
@ -13,12 +15,13 @@ fmt:
# run all checks # run all checks
test: typing lint test: typing lint
hatch run check hatch run check
@echo
@echo (set_color green)"all good ᕕ( ᐛ )ᕗ"(set_color normal)
# create hatch envs # create hatch envs
env: env:
#!/usr/bin/env fish for env in (hatch env show --json | jq 'keys[]' --raw-output); \
for env in (hatch env show --json | jq 'keys[]' --raw-output) hatch env create $env; \
hatch env create $env
end end
clean: clean:

View File

@ -59,11 +59,12 @@ def cli(roll: Roll | Literal["advantage"] | Literal["disadvantage"]) -> None:
throw = _advantage(roll) throw = _advantage(roll)
else: else:
throw = _throw(roll) throw = _throw(roll)
click.echo(f"total:\t{throw.total: >5}") total = f" {throw.total}"
click.secho(f"total:\t{total:╶>5}", bold=True)
if throw.is_critical_hit: # pragma: no cover (random) if throw.is_critical_hit: # pragma: no cover (random)
click.echo("critical hit!") click.secho("critical hit!", fg="green", bold=True)
elif throw.is_critical_miss: # pragma: no cover (random) elif throw.is_critical_miss: # pragma: no cover (random)
click.echo("critical miss!") click.secho("critical miss!", fg="red", bold=True)
def _advantage(advantage: str) -> Throw: def _advantage(advantage: str) -> Throw:
@ -72,8 +73,8 @@ def _advantage(advantage: str) -> Throw:
roll = Roll() roll = Roll()
fst = roll.throw() fst = roll.throw()
snd = roll.throw() snd = roll.throw()
click.echo(f"1:\t|{fst.total: >4}") click.echo(f"1:\t{fst.total: >5}")
click.echo(f"2:\t|{snd.total: >4}") click.echo(f"2:\t{snd.total: >5}")
if advantage == "advantage": if advantage == "advantage":
throw = fst if fst.total > snd.total else snd throw = fst if fst.total > snd.total else snd
else: else:
@ -86,7 +87,8 @@ def _throw(roll: Roll) -> Throw:
click.echo(f"throwing {roll.to_str()}:") click.echo(f"throwing {roll.to_str()}:")
throw = roll.throw() throw = roll.throw()
for i, result in enumerate(throw.results, start=1): for i, result in enumerate(throw.results, start=1):
click.echo(f"{i}:\t|{result: >4}") click.echo(f"{i}:\t{result: >5}")
if roll.modifier: if roll.modifier:
click.echo(f"mod:\t{roll.modifier_str(): >5}") color = "green" if roll.modifier > 0 else "red"
click.secho(f"mod:\t{roll.modifier_str(): >5}", fg=color)
return throw return throw

View File

@ -13,7 +13,7 @@ def runner() -> CliRunner:
def test_cli_smoke(runner: CliRunner): def test_cli_smoke(runner: CliRunner):
result = runner.invoke(cli, []) result = runner.invoke(cli, [])
assert result.exit_code == 0 assert result.exit_code == 0
assert result.output.startswith("throwing 1d20:\n1:\t|") assert result.output.startswith("throwing 1d20:\n1:\t")
assert "total" in result.output assert "total" in result.output
@ -22,7 +22,7 @@ def test_cli_roll(runner: CliRunner, value: str):
result = runner.invoke(cli, [value]) result = runner.invoke(cli, [value])
roll = Roll.from_str(value) roll = Roll.from_str(value)
assert result.exit_code == 0 assert result.exit_code == 0
assert result.output.startswith(f"throwing {value}:\n1:\t|") assert result.output.startswith(f"throwing {value}:\n1:\t")
assert len(result.output.splitlines()) >= roll.dice_count + 2 assert len(result.output.splitlines()) >= roll.dice_count + 2
assert "total" in result.output assert "total" in result.output
@ -31,5 +31,5 @@ def test_cli_roll(runner: CliRunner, value: str):
def test_cli_advantage(runner: CliRunner, advantage: str): def test_cli_advantage(runner: CliRunner, advantage: str):
result = runner.invoke(cli, [advantage]) result = runner.invoke(cli, [advantage])
assert result.exit_code == 0 assert result.exit_code == 0
assert result.output.startswith(f"throwing 2d20 with {advantage}:\n1:\t|") assert result.output.startswith(f"throwing 2d20 with {advantage}:\n1:\t")
assert "total" in result.output assert "total" in result.output