Skip to content

option: Add option to limit result list #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/cppman
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def main():
make_option('-v', '--version', action='store_true', dest='version',
default=False, help='Show version information.'),
make_option('--force-columns', action='store', dest='force_columns',
type=int, default=-1, help='Force terminal columns.')
type=int, default=-1, help='Force terminal columns.'),
make_option('-n','--max-results', action='store', dest='max_results',
type=int, default=-1, help='Maximum number of search results to show.')
]

parser = OptionParser(
Expand Down Expand Up @@ -159,7 +161,7 @@ def main():
sys.exit(1)

try:
keyword = cm.fuzzy_find(args[0])
keyword = cm.fuzzy_find(args[0], options.max_results)
if not keyword:
sys.exit(1)

Expand Down
4 changes: 3 additions & 1 deletion cppman/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,11 @@ def find(self, pattern):
else:
raise RuntimeError('%s: nothing appropriate.' % pattern)

def fuzzy_find(self, pattern):
def fuzzy_find(self, pattern, max_results):
"""Find pages in database and present an interactive selection menu."""
results = self._search_keyword(pattern)
if max_results >= 1:
results = results[:max_results]

if not results:
raise RuntimeError('%s: nothing appropriate.' % pattern)
Expand Down