Skip to content

Commit

Permalink
feat: command-line argument to choose digest to write.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 27, 2023
1 parent 9c02338 commit 4aae888
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions scriv.d/20230127_164615_nedbat_partial_33.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added
.....

- Now you can additionally specify digests on the command line to write, which
will choose just those digests from the configuration file.
8 changes: 6 additions & 2 deletions src/dinghy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ def main_run(coro):
@click_log.simple_verbosity_option(logger)
@click.version_option()
@click.argument("_input", metavar="[INPUT]", default="dinghy.yaml")
def cli(_input):
@click.argument("digests", metavar="[DIGEST ...]", nargs=-1)
def cli(_input, digests):
"""
Generate HTML digests of GitHub activity.
INPUT is a dinghy YAML configuration file (default: dinghy.yaml), or a
GitHub repo URL.
DIGEST(s) are the file names of digests from the configuration file to
create. If none are specified, all of the digests are written.
"""
if "://" in _input:
coro = make_digest([_input])
else:
coro = make_digests_from_config(_input)
coro = make_digests_from_config(_input, digests or None)

main_run(coro)
4 changes: 3 additions & 1 deletion src/dinghy/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ async def make_digest(items, since="1 week", digest="digest.html", **options):
logger.info(f"Wrote digest: {digest}")


async def make_digests_from_config(conf_file):
async def make_digests_from_config(conf_file, digests=None):
"""
Make all the digests specified by a configuration file.
Expand All @@ -562,6 +562,8 @@ async def make_digests_from_config(conf_file):
coros = []
for spec in config.get("digests", []):
args = {**defaults, **spec}
if digests is not None and args["digest"] not in digests:
continue
coros.append(make_digest(**args))
await asyncio.gather(*coros)

Expand Down

0 comments on commit 4aae888

Please sign in to comment.