1
0
Fork 0
mirror of synced 2024-06-01 10:09:49 +12:00

fix ag argument order

This commit is contained in:
Nick Sweeting 2017-06-18 05:59:55 -05:00
parent 09ffe38541
commit b6eb9d983f

View file

@ -9,7 +9,7 @@ if run(['which', 'ag'], stdout=DEVNULL, stderr=DEVNULL).returncode:
def search_archive(archive_path, pattern, regex=False):
args = '-gi' if regex else '-Qig'
args = '-ig' if regex else '-iQg'
ag = run(['ag', args, pattern, archive_path], stdout=PIPE, stderr=PIPE, timeout=60)
return (l.decode().replace(archive_path, '') for l in ag.stdout.splitlines())
@ -45,16 +45,20 @@ def server(port=8080):
if __name__ == '__main__':
argc = len(sys.argv)
if argc == 1 or sys.argv[2] in ('-h', '-v', '--help', 'help'):
print('Full-text search for a pattern in a given Bookmark Archiver archive.\nUsage:\n\t./search.py --server 8042 # Run a /archive/search?search=pattern&regex=1 REST server on 127.0.0.1:8042\n\t./search.py "pattern" pocket/archive # Find files containing "pattern" in the pocket/archive folder')
if argc == 1 or sys.argv[1] in ('-h', '-v', '--help', 'help'):
print('Full-text search for a pattern in a given Bookmark Archiver archive.\n'
'Usage:\n\t'
'./search.py --server 8042 # Run a /archive/search?search=pattern&regex=1 REST server on 127.0.0.1:8042\n\t'
'./search.py "pattern" pocket/archive # Find files containing "pattern" in the pocket/archive folder')
raise SystemExit(0)
if '--server' in sys.argv:
port = sys.argv[2] if argc > 2 else '8042'
server(port)
else:
pattern = sys.argv[2] if argc > 2 else sys.argv[1]
pattern = sys.argv[1]
archive_path = sys.argv[2] if argc > 2 else 'bookmarks/archive'
matches = search_archive(archive_path, pattern, regex=True)
# print(pattern, archive_path, len(list(matches)))
print('\n'.join(matches))