Use search option specific keyword lists

This commit is contained in:
Arun Prakash Jana 2018-03-13 07:28:16 +05:30
parent 1cb544fe1d
commit 33c126a068
No known key found for this signature in database
GPG Key ID: A75979F35C080412

50
buku.py
View File

@ -4046,11 +4046,11 @@ POSITIONAL ARGUMENTS:
excludes entries with tags after ' - ' excludes entries with tags after ' - '
list all tags, if no search keywords''') list all tags, if no search keywords''')
addarg = search_grp.add_argument addarg = search_grp.add_argument
addarg('-s', '--sany', action='store_true', help=HIDE) addarg('-s', '--sany', nargs='*', help=HIDE)
addarg('-S', '--sall', action='store_true', help=HIDE) addarg('-S', '--sall', nargs='*', help=HIDE)
addarg('-r', '--sreg', action='store_true', help=HIDE) addarg('-r', '--sreg', nargs='*', help=HIDE)
addarg('--deep', action='store_true', help=HIDE) addarg('--deep', action='store_true', help=HIDE)
addarg('-t', '--stag', action='store_true', help=HIDE) addarg('-t', '--stag', nargs='*', help=HIDE)
# ------------------------ # ------------------------
# ENCRYPTION OPTIONS GROUP # ENCRYPTION OPTIONS GROUP
@ -4262,7 +4262,7 @@ POSITIONAL ARGUMENTS:
else: else:
keywords = args.add + [DELIM] + tags_in keywords = args.add + [DELIM] + tags_in
if len(keywords) > 1: if len(keywords) > 1: # args.add is URL followed by optional tags
tags = parse_tags(keywords[1:]) tags = parse_tags(keywords[1:])
url = args.add[0] url = args.add[0]
@ -4294,29 +4294,39 @@ POSITIONAL ARGUMENTS:
search_opted = True search_opted = True
update_search_results = False update_search_results = False
if args.sany: if args.sany is not None:
# Search URLs, titles, tags for any keyword if len(args.sany):
search_results = bdb.searchdb(args.keywords, False, args.deep) # Search URLs, titles, tags for any keyword
elif args.sall: search_results = bdb.searchdb(args.sany, False, args.deep)
# Search URLs, titles, tags with all keywords else:
search_results = bdb.searchdb(args.keywords, True, args.deep) logerr('no keyword')
elif args.sreg: elif args.sall is not None:
# Run a regular expression search if len(args.sall):
search_results = bdb.searchdb(args.keywords, regex=True) # Search URLs, titles, tags with all keywords
elif args.stag: search_results = bdb.searchdb(args.sall, True, args.deep)
# Search bookmarks by tag else:
if args.keywords: logerr('no keyword')
search_results = bdb.search_by_tag(' '.join(args.keywords)) elif args.sreg is not None:
if len(args.sreg):
# Run a regular expression search
search_results = bdb.searchdb(args.sreg, regex=True)
else:
logerr('no expression')
elif args.stag is not None:
if len(args.stag):
# Search bookmarks by tag
search_results = bdb.search_by_tag(' '.join(args.stag))
else: else:
# Use sub prompt to list all tags # Use sub prompt to list all tags
prompt(bdb, None, args.np, subprompt=True, suggest=args.suggest) prompt(bdb, None, args.np, subprompt=True, suggest=args.suggest)
elif args.keywords: elif len(args.keywords):
# Search URLs, titles, tags for any keyword
search_results = bdb.searchdb(args.keywords, False, args.deep) search_results = bdb.searchdb(args.keywords, False, args.deep)
else: else:
search_opted = False search_opted = False
# Add cmdline search options to readline history # Add cmdline search options to readline history
if search_opted and args.keywords: if search_opted and len(args.keywords):
try: try:
readline.add_history(' '.join(args.keywords)) readline.add_history(' '.join(args.keywords))
except Exception: except Exception: