Skip to content

Commit

Permalink
feat: add beet.contrib.line_endings
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Sep 14, 2022
1 parent 37a23ce commit e6255fc
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions beet/contrib/line_endings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Plugin that configures line endings before writing out files."""


__all__ = [
"LineEndingsOptions",
"line_endings",
]


from typing import Any, Optional

from pydantic import BaseModel

from beet import Context, ListOption, TextFileBase, configurable


class LineEndingsOptions(BaseModel):
extensions: ListOption[str] = ListOption()
newline: Optional[str] = None


def beet_default(ctx: Context):
ctx.require(line_endings)


@configurable(validator=LineEndingsOptions)
def line_endings(ctx: Context, opts: LineEndingsOptions):
"""Plugin that configures line endings before writing out files."""
for pack in ctx.packs:
for _, text_file in pack.list_files(
*opts.extensions.entries(),
extend=TextFileBase[Any],
):
text_file.newline = opts.newline

0 comments on commit e6255fc

Please sign in to comment.