summaryrefslogtreecommitdiff
path: root/pygments/cmdline.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-11-11 18:35:55 +0100
committerGeorg Brandl <georg@python.org>2014-11-11 18:35:55 +0100
commit59f4e88549ddd1fa1ea010fa6f65efb0ef344dc4 (patch)
treed745f94f164e6172dbd70b63191d5b76b690eaef /pygments/cmdline.py
parent15f0c0409888d5fb148e9eb9d20c340acd73d4ea (diff)
downloadpygments-59f4e88549ddd1fa1ea010fa6f65efb0ef344dc4.tar.gz
Reorder logic in cmdline.main a bit.
Diffstat (limited to 'pygments/cmdline.py')
-rw-r--r--pygments/cmdline.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/pygments/cmdline.py b/pygments/cmdline.py
index 10b47f89..0dcda7ae 100644
--- a/pygments/cmdline.py
+++ b/pygments/cmdline.py
@@ -386,6 +386,20 @@ def main_inner(popts, args, usage):
except ClassNotFound:
lexer = TextLexer(**parsed_opts)
+ else: # -s option needs a lexer with -l
+ if not lexer:
+ print('Error: when using -s a lexer has to be selected with -l',
+ file=sys.stderr)
+ return 2
+
+ # process filters
+ for fname, fopts in F_opts:
+ try:
+ lexer.add_filter(fname, **fopts)
+ except ClassNotFound as err:
+ print('Error:', err, file=sys.stderr)
+ return 1
+
# select formatter
outfn = opts.pop('-o', None)
fmter = opts.pop('-f', None)
@@ -451,24 +465,12 @@ def main_inner(popts, args, usage):
right = escapeinside[1]
lexer = LatexEmbeddedLexer(left, right, lexer)
- # process filters
- for fname, fopts in F_opts:
- try:
- lexer.add_filter(fname, **fopts)
- except ClassNotFound as err:
- print('Error:', err, file=sys.stderr)
- return 1
-
# ... and do it!
if '-s' not in opts:
# process whole input as per normal...
highlight(code, lexer, fmter, outfile)
return 0
else:
- if not lexer:
- print('Error: when using -s a lexer has to be selected with -l',
- file=sys.stderr)
- return 2
# line by line processing of stdin (eg: for 'tail -f')...
try:
while 1: