Fix yaml support
This commit is contained in:
parent
f80d087ac4
commit
b43e972d1b
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = 'dnd-rolltable'
|
||||
version = '1.1'
|
||||
version = '1.1.1'
|
||||
license = 'The Unlicense'
|
||||
authors = ['Greg Boyington <evilchili@gmail.com>']
|
||||
description = 'Generate roll tables using weighted random distributions'
|
||||
|
|
|
@ -22,7 +22,10 @@ def create(
|
|||
help='The size of the die for which to create a table'),
|
||||
collapsed: bool = typer.Option(
|
||||
True,
|
||||
help='If True, collapse multiple die values with the same option.')
|
||||
help='If True, collapse multiple die values with the same option.'),
|
||||
yaml: bool = typer.Option(
|
||||
False,
|
||||
help='Render output as yaml.')
|
||||
):
|
||||
"""
|
||||
CLI for creating roll tables.
|
||||
|
@ -30,6 +33,10 @@ def create(
|
|||
|
||||
rt = tables.RollTable([Path(s).read_text() for s in sources], frequency=frequency, die=die)
|
||||
|
||||
if yaml:
|
||||
print(rt.as_yaml)
|
||||
return
|
||||
|
||||
rows = rt.rows if collapsed else rt.expanded_rows
|
||||
table = Table(*rows[0])
|
||||
for row in rows[1:]:
|
||||
|
|
|
@ -113,7 +113,10 @@ class RollTable:
|
|||
freqs = random.choices(options, weights=weights, k=self.die)
|
||||
values = []
|
||||
for option in freqs:
|
||||
choice = random.choice(ds.data[option]) if ds.data[option] else ''
|
||||
if not ds.data[option]:
|
||||
values.append([option])
|
||||
continue
|
||||
choice = random.choice(ds.data[option])
|
||||
if hasattr(choice, 'keys'):
|
||||
c = [option]
|
||||
for (k, v) in choice.items():
|
||||
|
@ -169,11 +172,9 @@ class RollTable:
|
|||
|
||||
@property
|
||||
def as_yaml(self) -> dict:
|
||||
struct = [{'headers': self.rows[0]}]
|
||||
struct = {'headers': self.rows[0]}
|
||||
for row in self.rows[1:]:
|
||||
struct.append({
|
||||
row[0]: row[1:]
|
||||
})
|
||||
struct[row[0]] = row[1:]
|
||||
return yaml.dump(struct)
|
||||
|
||||
def _config(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user