-
Notifications
You must be signed in to change notification settings - Fork 3
/
zeek-format
executable file
·52 lines (38 loc) · 1.22 KB
/
zeek-format
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
#!/usr/bin/env python
# pylint: disable=invalid-name
"""
This is a Zeek script formatter. It intentionally accepts no formatting
arguments. It writes any errors during processing to stderr. When errors arise,
it writes out unchanged input.
"""
# https://pypi.org/project/argcomplete/#global-completion
# PYTHON_ARGCOMPLETE_OK
import argparse
import sys
try:
# Argcomplete provides command-line completion for users of argparse.
# We support it if available, but don't complain when it isn't.
import argcomplete # pylint: disable=import-error
except ImportError:
pass
import zeekscript
# ---- Helper functions --------------------------------------------------------
def create_parser():
parser = argparse.ArgumentParser(description="A Zeek script formatter")
zeekscript.add_version_arg(parser)
zeekscript.add_format_cmd(parser)
if "argcomplete" in sys.modules:
argcomplete.autocomplete(parser)
return parser
def main():
parser = create_parser()
args = parser.parse_args()
if args.version:
print(zeekscript.__version__)
return 0
try:
return args.run_cmd(args)
except KeyboardInterrupt:
return 0
if __name__ == "__main__":
sys.exit(main())