Skip to content

Commit

Permalink
Allow main() to be passed the commandline arguments
Browse files Browse the repository at this point in the history
This makes it testable more easily
  • Loading branch information
etene committed Sep 4, 2017
1 parent 47a2b1d commit 77e1f78
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nldecap.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _yield_packets(self):
yield pkt_data


def main():
def main(args):
"""Parse arguments, read the pcap and parse nl packets with pyroute2"""
psr = ArgumentParser(description=__doc__.splitlines()[0])
psr.add_argument("pcap", type=FileType("rb"),
Expand All @@ -248,7 +248,7 @@ def main():
psr.add_argument("filter", nargs="*",
help="Only display messages of this type. "
"Can be specified multiple times.")
args = psr.parse_args()
args = psr.parse_args(args)
for i in args.filter:
if i not in MSG_TYPES:
psr.error("Invalid filter '%s' (choose from %s)" % (i, MSG_TYPES))
Expand Down Expand Up @@ -285,7 +285,9 @@ def main():
LOG.info("[packet %d] message %d (%s)",
pcap_file.pkt_count, msg_num, msg_type)
print_func(msg)
return 0


if __name__ == "__main__":
main()
import sys
sys.exit(main(sys.argv[1:]))

0 comments on commit 77e1f78

Please sign in to comment.