-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__main__.py
executable file
·59 lines (49 loc) · 1.53 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import itertools
import glob
import os
from . import __title__, __version__
from .kitsune import KitsunePrinter
def parse_args(args=None):
p = argparse.ArgumentParser(
prog="kitsune",
description="A prettier way to tail multiple files.",
add_help=False,
)
p.add_argument(
"--color",
metavar="<when>",
dest="color",
default="auto",
choices=["auto", "never", "always"],
help="""Specify when to use colored
output. The automatic mode only
enables colors if an interactive terminal is detected.
[default: auto] [possible values: auto, never, always]""",
)
p.add_argument("-h", "--help", action="help", help="Print this help message.")
p.add_argument(
"-V",
"--version",
action="version",
version="%(prog)s " + __version__,
help="Show version information.",
)
p.add_argument("pattern", nargs="+", help="Files to tail.")
parsed = p.parse_args(args=args)
return parsed
def main():
args = parse_args()
uses_color = args.color == "always" or (args.color == "auto" and os.isatty(0))
paths = map(glob.iglob, args.pattern)
paths = itertools.chain.from_iterable(paths)
# paths = map(os.path.abspath, paths)
paths = filter(os.path.isfile, paths)
paths = list(paths)
printer = KitsunePrinter(paths, uses_color)
printer.start()
printer.wait()
if __name__ == "__main__":
main()