Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add help text and YAML formatting arguments #35

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading