Skip to content

Commit

Permalink
updater: exit 1 on invalid operation
Browse files Browse the repository at this point in the history
  • Loading branch information
felixonmars committed Jan 20, 2019
1 parent 882bf12 commit 8a1ea4e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions updater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from __future__ import unicode_literals
from argparse import ArgumentParser
import sys

if __name__ == "__main__":
parser = ArgumentParser(description="dnsmasq-china-list updater")
Expand Down Expand Up @@ -34,6 +35,8 @@
with open(options.file[0]) as f:
lines = list(f)

changed = False

if options.add:
options.sort = True

Expand All @@ -44,6 +47,7 @@
else:
print("New domain added: " + domain)
lines.append(new_line)
changed = True

if options.delete:
options.sort = True
Expand All @@ -55,6 +59,10 @@
else:
print("Domain removed: " + domain)
lines.remove(target_line)
changed = True

if (options.add or options.delete) and not changed:
sys.exit(1)

if options.sort:
lines.sort(key=lambda x: x.lstrip("#"))
Expand Down

0 comments on commit 8a1ea4e

Please sign in to comment.