Group options.
This commit is contained in:
parent
0a314a0ad4
commit
7affa00442
78
buku
78
buku
@ -1014,56 +1014,71 @@ if len(pipeargs) > 0:
|
||||
|
||||
# Setup custom argument parser
|
||||
argparser = ExtendedArgumentParser(
|
||||
add_help=False,
|
||||
description='A private cmdline bookmark manager. Your mini web!',
|
||||
formatter_class=argparse.RawTextHelpFormatter
|
||||
formatter_class=argparse.RawTextHelpFormatter,
|
||||
usage='''buku [-a URL [tags ...]] [-u [N [URL tags ...]]]
|
||||
[-t title [...]] [-d [N]] [-h]
|
||||
[-s keyword [...]] [-S keyword [...]]
|
||||
[-k [N]] [-l [N]] [-p [N]] [-f N]
|
||||
[-r oldtag newtag] [-j] [-o N] [-z]''',
|
||||
add_help=False
|
||||
)
|
||||
addarg = argparser.add_argument
|
||||
|
||||
addarg('-a', '--add', nargs='+', dest='addurl', metavar=('URL', 'tags'),
|
||||
general_group = argparser.add_argument_group(title="general options")
|
||||
general_group.add_argument('-a', '--add', nargs='+', dest='addurl', metavar=('URL', 'tags'),
|
||||
help="bookmark URL with comma separated tags")
|
||||
addarg('-d', '--delete', nargs='?', dest='delete', type=int, const=0, metavar='N',
|
||||
general_group.add_argument('-u', '--update', nargs='*', dest='update', action=customAction, metavar=('N', 'URL tags'),
|
||||
help="update fields of bookmark at DB index N\n"
|
||||
"if URL is omitted (and -m unused), refresh\n"
|
||||
"title of bookmark at index N from the web;\n"
|
||||
"refresh all titles, if N is omitted")
|
||||
general_group.add_argument('-t', '--title', nargs='+', dest='titleManual', metavar='title',
|
||||
help="manually set title, works with -a, -u\n"
|
||||
"title='blank': no title")
|
||||
general_group.add_argument('-d', '--delete', nargs='?', dest='delete', type=int, const=0, metavar='N',
|
||||
help="delete bookmark at DB index N (from -p 0)\n"
|
||||
"delete all bookmarks, if N is omitted")
|
||||
addarg('-s', '--sany', nargs='+', metavar='KEYWORD',
|
||||
general_group.add_argument('-h', '--help', dest='help', action='store_true',
|
||||
help="show this information")
|
||||
|
||||
search_group=argparser.add_argument_group(title="search options")
|
||||
search_group.add_argument('-s', '--sany', nargs='+', metavar='keyword',
|
||||
help="search bookmarks for ANY matching keyword")
|
||||
addarg('-S', '--sall', nargs='+', metavar='KEYWORD',
|
||||
search_group.add_argument('-S', '--sall', nargs='+', metavar='keyword',
|
||||
help="search bookmarks with ALL keywords\n"
|
||||
"special keywords:\n"
|
||||
"'tags' - list all tags alphabetically\n"
|
||||
"'blank'- list entries with empty title/tag")
|
||||
addarg('-t', '--title', nargs='+', dest='titleManual', metavar='title',
|
||||
help="manually set title, works with -a, -u\n"
|
||||
"title='blank': no title")
|
||||
addarg('-u', '--update', nargs='*', dest='update', action=customAction, metavar=('N', 'URL tags'),
|
||||
help="update fields of bookmark at DB index N\n"
|
||||
"if URL is omitted (and -m unused), refresh\n"
|
||||
"title of bookmark at index N from the web;\n"
|
||||
"refresh all titles, if N is omitted")
|
||||
#addarg('-i', '--insert', nargs='+', dest='insert', metavar=('N', 'URL tags'),
|
||||
# help=" insert new bookmark with URL and tags at free DB index N; frees index if URL and tags are omitted")
|
||||
addarg('-j', '--json', dest='jsonOutput', action='store_true',
|
||||
help="Json formatted output, works with -p, -s")
|
||||
addarg('-k', '--unlock', nargs='?', dest='decrypt', type=int, const=8, metavar='N',
|
||||
|
||||
crypto_group=argparser.add_argument_group(title="encryption options")
|
||||
crypto_group.add_argument('-k', '--unlock', nargs='?', dest='decrypt', type=int, const=8, metavar='N',
|
||||
help="decrypt DB file with N (> 0, default 8)\n"
|
||||
"hash iterations to generate key")
|
||||
addarg('-l', '--lock', nargs='?', dest='encrypt', type=int, const=8, metavar='N',
|
||||
crypto_group.add_argument('-l', '--lock', nargs='?', dest='encrypt', type=int, const=8, metavar='N',
|
||||
help="encrypt DB file with N (> 0, default 8)\n"
|
||||
"hash iterations to generate key")
|
||||
addarg('-o', '--open', dest='openurl', type=int, metavar='N',
|
||||
help="open bookmark at DB index N in web browser")
|
||||
addarg('-p', '--print', nargs='?', dest='printindex', type=int, const=0, metavar='N',
|
||||
|
||||
power_group=argparser.add_argument_group(title="power toys")
|
||||
power_group.add_argument('-p', '--print', nargs='?', dest='printindex', type=int, const=0, metavar='N',
|
||||
help="show details of bookmark at DB index N\n"
|
||||
"show all bookmarks, if N is omitted")
|
||||
addarg('-r', '--replace', nargs=2, dest='replace', metavar=('oldtag', 'newtag'),
|
||||
help="replace oldtag with newtag for all bookmarks\n"
|
||||
"newtag='blank': delete oldtag")
|
||||
addarg('-f', '--format', dest='showOpt', type=int, choices=[1, 2], metavar='N',
|
||||
power_group.add_argument('-f', '--format', dest='showOpt', type=int, choices=[1, 2], metavar='N',
|
||||
help="modify -p output\n"
|
||||
"N=1: show only URL, N=2: show URL and tag")
|
||||
addarg('-z', '--debug', dest='debug', action='store_true',
|
||||
power_group.add_argument('-r', '--replace', nargs=2, dest='replace', metavar=('oldtag', 'newtag'),
|
||||
help="replace oldtag with newtag for all bookmarks\n"
|
||||
"newtag='blank': delete oldtag")
|
||||
power_group.add_argument('-j', '--json', dest='jsonOutput', action='store_true',
|
||||
help="Json formatted output, works with -p, -s")
|
||||
power_group.add_argument('-o', '--open', dest='openurl', type=int, metavar='N',
|
||||
help="open bookmark at DB index N in web browser")
|
||||
power_group.add_argument('-z', '--debug', dest='debug', action='store_true',
|
||||
help="show debug information and additional logs")
|
||||
|
||||
#addarg = argparser.add_argument
|
||||
#addarg('-i', '--insert', nargs='+', dest='insert', metavar=('N', 'URL tags'),
|
||||
# help=" insert new bookmark with URL and tags at free DB index N; frees index if URL and tags are omitted")
|
||||
|
||||
# Show help if no arguments passed
|
||||
if len(sys.argv) < 2:
|
||||
argparser.print_help(sys.stderr)
|
||||
@ -1072,6 +1087,11 @@ if len(sys.argv) < 2:
|
||||
# Parse the arguments
|
||||
args = argparser.parse_args()
|
||||
|
||||
# Show help and exit if help requested
|
||||
if args.help == True:
|
||||
argparser.print_help(sys.stderr)
|
||||
sys.exit(0)
|
||||
|
||||
# Assign the values to globals
|
||||
if args.showOpt is not None:
|
||||
showOpt = args.showOpt
|
||||
|
Loading…
Reference in New Issue
Block a user