fix ag argument order
This commit is contained in:
parent
09ffe38541
commit
b6eb9d983f
12
search.py
12
search.py
|
@ -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®ex=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®ex=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))
|
||||
|
|
Loading…
Reference in a new issue