Omit title if -t is used without arguments.

This commit is contained in:
Arun Prakash Jana 2016-04-27 23:26:57 +05:30
parent 1549f51bf8
commit 99ebbac663
No known key found for this signature in database
GPG Key ID: C0A712ED95043DCB

41
buku
View File

@ -387,9 +387,6 @@ def AddUpdateEntry(conn, cur, keywords, updateindex, insertindex=0):
tags += ','
if titleManual is not None:
if titleManual == BLANK:
meta = ''
else:
meta = titleManual
else:
meta = fetchTitle(url)
@ -457,9 +454,6 @@ def dbRefresh(conn, cur, index):
cur.execute("UPDATE bookmarks SET metadata = ? WHERE id = ?", (title, row[0],))
conn.commit()
print("Updated index %d\n" % row[0])
else:
if titleManual == BLANK:
title = ''
else:
title = titleManual
@ -955,7 +949,7 @@ def printmsg(msg, level=None):
class customAction(argparse.Action):
class customUpdateAction(argparse.Action):
"""Class to capture if an optional param
is actually used, even if sans arguments
"""
@ -969,6 +963,22 @@ class customAction(argparse.Action):
class customTitleAction(argparse.Action):
"""Class to capture if an optional param
is actually used, even if sans arguments
"""
def __call__(self, parser, args, values, option_string=None):
global titleManual
titleManual = ''
if titleManual is not None:
print("titleManual is not None")
# NOTE: the following converts a None argument to an empty array []
setattr(args, self.dest, values)
class ExtendedArgumentParser(argparse.ArgumentParser):
"""Extend classic argument parser"""
@ -1017,7 +1027,7 @@ argparser = ExtendedArgumentParser(
description='A private cmdline bookmark manager. Your mini web!',
formatter_class=argparse.RawTextHelpFormatter,
usage='''buku [-a URL [tags ...]] [-u [N [URL tags ...]]]
[-t title [...]] [-d [N]] [-h]
[-t [...]] [-d [N]] [-h]
[-s keyword [...]] [-S keyword [...]]
[-k [N]] [-l [N]] [-p [N]] [-f N]
[-r oldtag newtag] [-j] [-o N] [-z]''',
@ -1033,15 +1043,14 @@ general_group = argparser.add_argument_group(title="general options",
refresh all titles, if no arguments
if URL omitted and -t is unused, update
title of bookmark at index N from web
-t, --title title [...]
manually set title, works with -a, -u
title='blank': no title
-t, --title [...] manually set title, works with -a, -u
do not set title, is no arguments
-d, --delete [N] delete bookmark at DB index N
delete all bookmarks, if no arguments
-h, --help show this information''')
general_group.add_argument('-a', '--add', nargs='+', dest='addurl', metavar=('URL', 'tags'), help=argparse.SUPPRESS)
general_group.add_argument('-u', '--update', nargs='*', dest='update', action=customAction, metavar=('N', 'URL tags'), help=argparse.SUPPRESS)
general_group.add_argument('-t', '--title', nargs='+', dest='titleManual', metavar='title', help=argparse.SUPPRESS)
general_group.add_argument('-u', '--update', nargs='*', dest='update', action=customUpdateAction, metavar=('N', 'URL tags'), help=argparse.SUPPRESS)
general_group.add_argument('-t', '--title', nargs='*', dest='title', action=customTitleAction, metavar='title', help=argparse.SUPPRESS)
general_group.add_argument('-d', '--delete', nargs='?', dest='delete', type=int, const=0, metavar='N', help=argparse.SUPPRESS)
general_group.add_argument('-h', '--help', dest='help', action='store_true', help=argparse.SUPPRESS)
@ -1073,7 +1082,7 @@ power_group=argparser.add_argument_group(title="power toys",
-f, --format N modify -p output
N=1: show only URL, N=2: show URL and tag
-r, --replace oldtag newtag
replace oldtag with newtag for all bookmarks
replace oldtag with newtag in all bookmarks
newtag='blank': delete oldtag
-j, --jason Json formatted output, works with -p, -s
-o, --open open bookmark at DB index N in web browser
@ -1105,8 +1114,8 @@ if args.help == True:
# Assign the values to globals
if args.showOpt is not None:
showOpt = args.showOpt
if args.titleManual is not None:
titleManual = " ".join(args.titleManual)
if titleManual is not None and len(args.title) > 0:
titleManual = " ".join(args.title)
jsonOutput = args.jsonOutput
debug = args.debug