diff options
-rw-r--r-- | lesana/command.py | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/lesana/command.py b/lesana/command.py index dd1864a..56c855a 100644 --- a/lesana/command.py +++ b/lesana/command.py @@ -139,27 +139,35 @@ class Index(guacamole.Command): class Search(guacamole.Command): arguments = [ - (['--collection', '-c'], dict( + ] + + def register_arguments(self, parser): + parser.add_argument( + '--collection', '-c', help='The collection to work on (default .)' - )), - (['--template', '-t'], dict( + ) + parser.add_argument( + '--template', '-t', help='Am', - )), - (['--offset'], dict( + ), + parser.add_argument( + '--offset', type=int, - )), - (['--pagesize'], dict( + ), + parser.add_argument( + '--pagesize', type=int, - )), - (['query'], dict( + ), + parser.add_argument( + '--all', + action='store_true', + help='Return all available results' + ) + parser.add_argument( + 'query', help='Xapian query to search in the collection', nargs='+' - )), - ] - - def register_arguments(self, parser): - for arg in self.arguments: - parser.add_argument(*arg[0], **arg[1]) + ), def invoked(self, ctx): # TODO: implement "searching" for everything @@ -177,9 +185,12 @@ class Search(guacamole.Command): pagesize = ctx.args.pagesize or 12 collection = Collection(ctx.args.collection) collection.start_search(' '.join(ctx.args.query)) - results = collection.get_search_results( - offset, - pagesize) + if ctx.args.all: + results = collection.get_all_search_results() + else: + results = collection.get_search_results( + offset, + pagesize) if ctx.args.template: env = jinja2.Environment( loader=jinja2.FileSystemLoader( |