Skip to content

Commit fae69af

Browse files
committed
explicit options
1 parent bf2db5f commit fae69af

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

html5validator/cli.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def main():
2828
parser.add_argument('--show-warnings', dest='errors_only',
2929
action='store_false', default=True,
3030
help='show warnings')
31-
parser.add_argument('--no-langdetect',
32-
action='store_true', default=False,
31+
parser.add_argument('--no-langdetect', dest='detect_language',
32+
action='store_false', default=True,
3333
help='disable language detection')
3434
parser.add_argument('--format', choices=['gnu', 'xml', 'json', 'text'],
3535
help='output format', default=None)
@@ -64,28 +64,17 @@ def main():
6464
version='%(prog)s ' + VERSION)
6565
args = parser.parse_args()
6666

67-
vnu_options = []
68-
if args.errors_only:
69-
vnu_options.append('--errors_only')
70-
if args.no_langdetect:
71-
vnu_options.append('--no-langdetect')
72-
if args.format:
73-
vnu_options.append('--format')
74-
vnu_options.append(args.format)
75-
76-
java_options = []
77-
if args.stack_size:
78-
java_options.append('-Xss{}k'.format(args.stack_size))
79-
8067
logging.basicConfig(level=getattr(logging, args.log))
8168

8269
validator = Validator(directory=args.root,
8370
match=args.match,
8471
blacklist=args.blacklist,
8572
ignore=args.ignore,
8673
ignore_re=args.ignore_re,
87-
java_options=java_options,
88-
vnu_options=vnu_options)
74+
errors_only=args.errors_only,
75+
detect_language=args.detect_language,
76+
format=args.format,
77+
stack_size=args.stack_size)
8978
files = validator.all_files()
9079
LOGGER.info('Files to validate: \n {0}'.format('\n '.join(files)))
9180
LOGGER.info('Number of files: {0}'.format(len(files)))

html5validator/validator.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ class Validator(object):
2626

2727
def __init__(self, directory='.', match='*.html', blacklist=None,
2828
ignore=None, ignore_re=None,
29-
java_options=None, vnu_options=None):
29+
errors_only=False, detect_language=True, format=None,
30+
stack_size=None):
3031
self.directory = directory
3132
self.match = match
3233
self.blacklist = blacklist if blacklist else []
3334
self.ignore = ignore if ignore else []
3435
self.ignore_re = ignore_re if ignore_re else []
35-
self.java_options = java_options if java_options is not None else []
36-
self.vnu_options = vnu_options if vnu_options is not None else []
36+
37+
# java options
38+
self.stack_size = stack_size
39+
40+
# vnu options
41+
self.errors_only = errors_only
42+
self.detect_language = detect_language
43+
self.format = format
3744

3845
# add default ignore_re
3946
self.ignore_re += DEFAULT_IGNORE_RE
@@ -50,6 +57,29 @@ def __init__(self, directory='.', match='*.html', blacklist=None,
5057
self.vnu_jar_location = self._cygwin_path_convert(
5158
self.vnu_jar_location)
5259

60+
@property
61+
def _java_options(self):
62+
java_options = []
63+
64+
if self.stack_size is not None:
65+
java_options.append('-Xss{}k'.format(self.stack_size))
66+
67+
return java_options
68+
69+
@property
70+
def _vnu_options(self):
71+
vnu_options = []
72+
73+
if self.errors_only:
74+
vnu_options.append('--errors_only')
75+
if not self.detect_language:
76+
vnu_options.append('--no-langdetect')
77+
if self.format is not None:
78+
vnu_options.append('--format')
79+
vnu_options.append(self.format)
80+
81+
return vnu_options
82+
5383
def _normalize_string(self, s):
5484
s = s.replace('“', '"')
5585
s = s.replace('”', '"')
@@ -93,8 +123,8 @@ def validate(self, files=None):
93123
raise JavaNotFoundException()
94124

95125
try:
96-
cmd = (['java'] + self.java_options +
97-
['-jar', self.vnu_jar_location] + self.vnu_options + files)
126+
cmd = (['java'] + self._java_options +
127+
['-jar', self.vnu_jar_location] + self._vnu_options + files)
98128
o = subprocess.check_output(
99129
cmd,
100130
stderr=subprocess.STDOUT,

0 commit comments

Comments
 (0)