From afaa97cd11ab58c88bf74fdaa8ddd3eb109ad740 Mon Sep 17 00:00:00 2001 From: Morgan Courbet Date: Sat, 17 Jun 2017 19:45:39 +0200 Subject: [PATCH] Add enum to mixed_line_ending `--fix` option --- pre_commit_hooks/mixed_line_ending.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pre_commit_hooks/mixed_line_ending.py b/pre_commit_hooks/mixed_line_ending.py index bc863be..7b7cabe 100644 --- a/pre_commit_hooks/mixed_line_ending.py +++ b/pre_commit_hooks/mixed_line_ending.py @@ -4,22 +4,34 @@ import sys from enum import Enum -class LineEnding(Enum): +class CLIOption(Enum): + def __init__(self, optName): + self.optName = optName + + +class LineEnding(CLIOption): CRLF = '\r\n', '\\r\\n', 'crlf' LF = '\n', '\\n', 'lf' - def __init__(self, str, strPrint, optName): - self.str = str + def __init__(self, string, strPrint, optName): + self.string = string self.strPrint = strPrint self.optName = optName +class MixedLineEndingOption(CLIOption): + AUTO = 'auto' + NO = 'no' + CRLF = LineEnding.CRLF.optName + LF = LineEnding.LF.optName + + def mixed_line_ending(argv=None): parser = argparse.ArgumentParser() parser.add_argument( '-f', '--fix', - choices=['auto', 'no'] + [m.optName for m in LineEnding], + choices=[m.optName for m in MixedLineEndingOption], default='auto', help='Replace line ending with the specified. Default is "auto"', nargs=1)