Skip to content

Commit 4e14981

Browse files
authored
Merge pull request #98 from yanhuihang/master
[v1.0.8] Add command line
2 parents d2d0522 + 16434fc commit 4e14981

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

filetype/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
from .match import * # noqa
88

99
# Current package semver version
10-
__version__ = version = '1.0.7'
10+
__version__ = version = '1.0.8'

filetype/__main__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import filetype
2+
3+
def guess(path):
4+
kind = filetype.guess(path)
5+
if kind is None:
6+
print('{}: File type determination failure.'.format(path))
7+
else:
8+
print('{}: {} ({})'.format(path, kind.extension, kind.mime))
9+
10+
def main():
11+
import argparse
12+
13+
parser = argparse.ArgumentParser(description='Determine type of FILEs.')
14+
parser.add_argument("file", nargs='+')
15+
parser.add_argument('-v', '--version', action='store_true',
16+
help='output version information and exit')
17+
args = parser.parse_args()
18+
19+
if args.version:
20+
print(filetype.version)
21+
else:
22+
for i in args.file:
23+
guess(i)
24+
25+
if __name__ == '__main__':
26+
main()

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='filetype',
9-
version='1.0.7',
9+
version='1.0.8',
1010
description='Infer file type and MIME type of any file/buffer. '
1111
'No external dependencies.',
1212
long_description=codecs.open('README.rst', 'r',
@@ -39,4 +39,7 @@
3939
packages=find_packages(exclude=['dist', 'build', 'docs', 'tests',
4040
'examples']),
4141
package_data={'filetype': ['LICENSE', '*.md']},
42-
zip_safe=True)
42+
zip_safe=True,
43+
entry_points = {
44+
'console_scripts': [ 'filetype=filetype.__main__:main' ],
45+
})

0 commit comments

Comments
 (0)