title can have multiple tokens.
This commit is contained in:
parent
045eec9467
commit
5c1105e950
50
buku
50
buku
@ -955,23 +955,6 @@ def printmsg(msg, level=None):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""main starts here"""
|
|
||||||
def main(argv = sys.argv):
|
|
||||||
# detects whether have pipe line parsing in
|
|
||||||
if not sys.stdin.isatty():
|
|
||||||
pipeargs.extend(sys.argv)
|
|
||||||
for s in sys.stdin.readlines():
|
|
||||||
pipeargs.extend(s.split())
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
try:
|
|
||||||
main(sys.argv)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if len(pipeargs) > 0:
|
|
||||||
sys.argv = pipeargs
|
|
||||||
|
|
||||||
class customAction(argparse.Action):
|
class customAction(argparse.Action):
|
||||||
"""Class to capture if an optional param
|
"""Class to capture if an optional param
|
||||||
is actually used, even if sans arguments
|
is actually used, even if sans arguments
|
||||||
@ -984,6 +967,8 @@ class customAction(argparse.Action):
|
|||||||
# NOTE: the following converts a None argument to an empty array []
|
# NOTE: the following converts a None argument to an empty array []
|
||||||
setattr(args, self.dest, values)
|
setattr(args, self.dest, values)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExtendedArgumentParser(argparse.ArgumentParser):
|
class ExtendedArgumentParser(argparse.ArgumentParser):
|
||||||
"""Extend classic argument parser"""
|
"""Extend classic argument parser"""
|
||||||
|
|
||||||
@ -1006,6 +991,28 @@ class ExtendedArgumentParser(argparse.ArgumentParser):
|
|||||||
super(ExtendedArgumentParser, self).print_help(file)
|
super(ExtendedArgumentParser, self).print_help(file)
|
||||||
self.print_extended_help(file)
|
self.print_extended_help(file)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""main starts here"""
|
||||||
|
|
||||||
|
# Handle piped input
|
||||||
|
def main(argv = sys.argv):
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
pipeargs.extend(sys.argv)
|
||||||
|
for s in sys.stdin.readlines():
|
||||||
|
pipeargs.extend(s.split())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
main(sys.argv)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# If piped input, set argument vector
|
||||||
|
if len(pipeargs) > 0:
|
||||||
|
sys.argv = pipeargs
|
||||||
|
|
||||||
|
# Setup custom argument parser
|
||||||
argparser = ExtendedArgumentParser(
|
argparser = ExtendedArgumentParser(
|
||||||
add_help=False,
|
add_help=False,
|
||||||
description='A private cmdline bookmark manager. Your mini web!',
|
description='A private cmdline bookmark manager. Your mini web!',
|
||||||
@ -1025,9 +1032,9 @@ addarg('-S', '--sall', nargs='+', metavar='KEYWORD',
|
|||||||
"special keywords:\n"
|
"special keywords:\n"
|
||||||
"'tags' - list all tags alphabetically\n"
|
"'tags' - list all tags alphabetically\n"
|
||||||
"'blank'- list entries with empty title/tag")
|
"'blank'- list entries with empty title/tag")
|
||||||
addarg('-t', '--title', dest='titleManual', metavar='title',
|
addarg('-t', '--title', nargs='+', dest='titleManual', metavar='title',
|
||||||
help="manually set title, works with -a, -u\n"
|
help="manually set title, works with -a, -u\n"
|
||||||
"title='blank': clear title")
|
"title='blank': no title")
|
||||||
addarg('-u', '--update', nargs='*', dest='update', action=customAction, metavar=('N', 'URL tags'),
|
addarg('-u', '--update', nargs='*', dest='update', action=customAction, metavar=('N', 'URL tags'),
|
||||||
help="update fields of bookmark at DB index N\n"
|
help="update fields of bookmark at DB index N\n"
|
||||||
"if URL is omitted (and -m unused), refresh\n"
|
"if URL is omitted (and -m unused), refresh\n"
|
||||||
@ -1057,16 +1064,19 @@ addarg('-x', '--format', dest='showOpt', type=int, choices=[1, 2], metavar='N',
|
|||||||
addarg('-z', '--debug', dest='debug', action='store_true',
|
addarg('-z', '--debug', dest='debug', action='store_true',
|
||||||
help="show debug information and additional logs")
|
help="show debug information and additional logs")
|
||||||
|
|
||||||
|
# Show help if no arguments passed
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
argparser.print_help(sys.stderr)
|
argparser.print_help(sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Parse the arguments
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
# Assign the values to globals
|
# Assign the values to globals
|
||||||
if args.showOpt is not None:
|
if args.showOpt is not None:
|
||||||
showOpt = args.showOpt
|
showOpt = args.showOpt
|
||||||
titleManual = args.titleManual
|
if args.titleManual is not None:
|
||||||
|
titleManual = " ".join(args.titleManual)
|
||||||
jsonOutput = args.jsonOutput
|
jsonOutput = args.jsonOutput
|
||||||
debug = args.debug
|
debug = args.debug
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user