forked from logan62334/python-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
61 lines (46 loc) · 1.16 KB
/
Copy pathcli.py
File metadata and controls
61 lines (46 loc) · 1.16 KB
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
60
61
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
proxy.cli
~~~~~~~~~~~~
This module is the main of proxy.
:copyright: (c) 2017 by Ma Fei.
"""
import logging
import os
import signal
import click
import proxy
logger = logging.getLogger(__name__)
def output_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
click.echo("Version: {}".format(proxy.__version__))
ctx.exit()
@click.command()
@click.option(
'-v',
'--version',
is_flag=True,
is_eager=True,
callback=output_version,
expose_value=False,
help="show the version of this tool")
@click.option(
'-l',
'--log',
default='INFO',
help='Specify logging level, default is INFO')
def parse_command(log):
log_level = getattr(logging, log.upper())
logging.basicConfig(level=log_level)
def signal_handler(signum, frame):
logger.info("main process(%d) got GracefulExitException" % os.getpid())
os._exit(0)
def main():
print("A Terminal Tools For proxy")
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
parse_command()
if __name__ == "__main__":
main()