Skip to content

Commit dc393ad

Browse files
committed
Implement support for execution from command-line
To use 'csscompressor' as a command-line tool, simply run $ python3 -m csscompressor --help Support: Python 2.7 & 3.3
1 parent ef0381c commit dc393ad

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Usage
1515
... ''')
1616
'your css{content:"!"}'
1717
18+
Or, if you want to use it from command line:
19+
20+
.. code::
21+
22+
$ python3 -m csscompressor --help
23+
1824
1925
Compatibility
2026
=============

csscompressor/__main__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
##
2+
# Copyright (c) 2013 Sprymix Inc.
3+
# All rights reserved.
4+
#
5+
# See LICENSE for details.
6+
##
7+
8+
9+
import argparse
10+
import csscompressor
11+
12+
13+
def _get_args():
14+
parser = argparse.ArgumentParser()
15+
16+
parser.add_argument('input', nargs='+', type=str,
17+
help='File(s) to compress')
18+
parser.add_argument('--line-break', type=int, metavar='<column>',
19+
help='Insert a line break after the specified column number')
20+
parser.add_argument('-o', '--output', type=str, metavar='<file>',
21+
help='Place the output into <file>. Defaults to stdout')
22+
23+
args = parser.parse_args()
24+
return args
25+
26+
27+
def main():
28+
args = _get_args()
29+
30+
buffer = []
31+
for name in args.input:
32+
with open(name, 'rt') as f:
33+
buffer.append(f.read())
34+
buffer = '\n\n'.join(buffer)
35+
36+
line_break = 0
37+
if args.line_break is not None:
38+
line_break = args.line_break
39+
40+
output = csscompressor.compress(buffer, max_linelen=line_break)
41+
42+
if args.output:
43+
with open(args.output, 'wt') as f:
44+
f.write(output)
45+
f.write('\n')
46+
else:
47+
print(output)
48+
49+
50+
main()

setup.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
f.close()
1010

1111

12+
deps = []
13+
try:
14+
import argparse
15+
except ImportError:
16+
deps.append('argparse')
17+
18+
1219
setup(
1320
name='csscompressor',
1421
version='0.9.0',
@@ -24,9 +31,13 @@
2431
'Operating System :: OS Independent',
2532
'Programming Language :: Python',
2633
'Programming Language :: Python :: 3',
27-
'Programming Language :: Python :: 2',
28-
'Topic :: Text Processing :: General'
34+
'Programming Language :: Python :: 2.7',
35+
'Programming Language :: Python :: 2.6',
36+
'Topic :: Software Development :: Build Tools',
37+
'Topic :: Text Processing :: General',
38+
'Topic :: Utilities'
2939
],
3040
packages=['csscompressor', 'csscompressor.tests'],
41+
install_requires=deps,
3142
**extra
3243
)

0 commit comments

Comments
 (0)