Skip to content

Commit 4165860

Browse files
committed
Add --version switch to formatHTML, and add version output to --help message.
1 parent 6a23f24 commit 4165860

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

formatHTML

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import sys
1414

1515
from AdvancedHTMLParser import AdvancedHTMLFormatter, AdvancedHTMLMiniFormatter, AdvancedHTMLSlimTagFormatter, AdvancedHTMLSlimTagMiniFormatter
1616

17+
from AdvancedHTMLParser import __version__ as VERSION
18+
19+
def printVersion():
20+
sys.stdout.write ( 'AdvancedHTMLParser and formatHTML by Timothy Savannah (c) 2015-2018 Version %s\n\n' %(VERSION, ))
1721

1822
def printUsage():
1923
sys.stderr.write('''Usage: %s (Optional Arguments) (optional: /path/to/in.html) (optional: [/path/to/output.html])
@@ -37,11 +41,17 @@ def printUsage():
3741
level of nesting. Use --indent="\t" for 1 tab insead, for example.
3842
Affects pretty printing mode only
3943
44+
--version - Print version info on AdvancedHTMLParser suite and exit
45+
46+
--help - Print this message and exit
47+
4048
4149
If output filename is not specified or is empty string, output will be to stdout.
4250
If input filename is not specified or is empty string, input will be from stdin
4351
If -e is provided, will use that as the encoding. Defaults to utf-8
52+
4453
''' %(os.path.basename(sys.argv[0])))
54+
printVersion()
4555

4656
if __name__ == '__main__':
4757

@@ -90,7 +100,10 @@ if __name__ == '__main__':
90100
isSlim = True
91101
elif arg == '--help':
92102
printUsage()
93-
sys.exit(1)
103+
sys.exit(0)
104+
elif arg == '--version':
105+
printVersion()
106+
sys.exit(0)
94107
elif inFilename is None:
95108
inFilename = arg
96109
elif outFilename is None:

0 commit comments

Comments
 (0)