Skip to content

Commit

Permalink
Merge pull request #35 from pre-commit/update
Browse files Browse the repository at this point in the history
Add help text and YAML formatting arguments
  • Loading branch information
mxr authored Jun 27, 2024
2 parents 14ae709 + d03e6b4 commit a7da3d1
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions sync_pre_commit_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,44 @@
SUPPORTED = frozenset(('black', 'flake8'))


_ARGUMENT_HELP_TEMPLATE = (
'The `{}` argument to the YAML dumper. '
'See https://yaml.readthedocs.io/en/latest/detail/'
'#indentation-of-block-sequences'
)


def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filename', default='.pre-commit-config.yaml')
parser.add_argument(
'filename', default='.pre-commit-config.yaml',
help='The pre-commit config file to sync to.',
)

# defaults below match pre-commit config as documented
# TODO - support round-tripping
parser.add_argument(
'--yaml-mapping', type=int, default=4,
help=_ARGUMENT_HELP_TEMPLATE.format('mapping'),
)
parser.add_argument(
'--yaml-sequence', type=int, default=4,
help=_ARGUMENT_HELP_TEMPLATE.format('sequence'),
)
parser.add_argument(
'--yaml-offset', type=int, default=0,
help=_ARGUMENT_HELP_TEMPLATE.format('offset'),
)

args = parser.parse_args(argv)
filename: str = args.filename
yaml_mapping: int = args.yaml_mapping
yaml_sequence: int = args.yaml_sequence
yaml_offset: int = args.yaml_offset

# match pre-commit config as documented
# TODO - support round-tripping
yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
yaml.indent(mapping=4, sequence=4)
yaml.indent(yaml_mapping, yaml_sequence, yaml_offset)

with open(filename) as f:
loaded = yaml.load(f)
Expand Down

0 comments on commit a7da3d1

Please sign in to comment.