Skip to content

Commit

Permalink
simplify cli
Browse files Browse the repository at this point in the history
  • Loading branch information
kjaymiller committed Nov 6, 2024
1 parent d2d55f2 commit 9e5af7d
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions update_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@
app = typer.Typer(no_args_is_help=True)


def fix_file(target_file: pathlib.Path):
fm_file = frontmatter.loads(target_file.read_text())

if "layout" not in fm_file.metadata:
fm_file["layout"] = "post"
target_file.write_text(frontmatter.dumps(fm_file))


@app.command(name="fix")
def fix_files(
target_files: typing.List[pathlib.Path],
) -> None:
"""Adds the default layout if the post is missing."""
for target_file in target_files:
fix_file(target_file)


@app.command(name="check")
def check_file(
target_files: typing.List[pathlib.Path],
Expand All @@ -36,7 +19,8 @@ def check_file(

if "layout" not in fm_file.metadata:
print("%s is missing the `layout` value. Applying layout: post.")
fix_file(target_file)
fm_file["layout"] = "post"
target_file.write_text(frontmatter.dumps(fm_file))
ret_code = 1

typer.Exit(code=ret_code)
Expand Down

0 comments on commit 9e5af7d

Please sign in to comment.