Skip to content

Commit

Permalink
Rearrange suggest output and sys.exit
Browse files Browse the repository at this point in the history
Closes #262 anc closes #263.
  • Loading branch information
bskinn committed Nov 23, 2022
1 parent 1cce07b commit 648d3e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
23 changes: 18 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ For internal cross-references, locate ``objects.inv`` within ``build/html``::

$ sphobjinv suggest doc/build/html/objects.inv as_rst -st 58

------------------------------------------------

Cannot infer intersphinx_mapping from a local objects.inv.

------------------------------------------------

Project: sphobjinv
Version: 2.3

219 objects in inventory.

------------------------------------------------

11 results found at/above current threshold of 58.

Cannot infer intersphinx_mapping from a local objects.inv.

Name Score
--------------------------------------------------- -------
Expand Down Expand Up @@ -103,16 +110,22 @@ cross-reference the ``linspace`` function from numpy (see
Attempting "https://numpy.org/doc/1.23/objects.inv" ...
... inventory found.

------------------------------------------------

The intersphinx_mapping for this docset is LIKELY:

(https://numpy.org/doc/1.23/, None)

------------------------------------------------

Project: NumPy
Version: 1.23

8074 objects in inventory.

8 results found at/above current threshold of 75.

The intersphinx_mapping for this docset is LIKELY:
------------------------------------------------

(https://numpy.org/doc/1.23/, None)
8 results found at/above current threshold of 75.


Name Score
Expand Down
16 changes: 14 additions & 2 deletions src/sphobjinv/cli/suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ def do_suggest(inv, params):
with_score=with_score,
)

print_divider(params)
print_stderr_inferred_mapping(params)
print_divider(params)

print_stderr(f"Project: {inv.project}", params)
print_stderr(f"Version: {inv.version}\n", params)

print_stderr(f"{inv.count} objects in inventory.\n", params)
print_divider(params)

print_stderr_result_count(params, results)

print_stderr_inferred_mapping(params)
if not results:
print_stderr("\nExiting...\n", params)
sys.exit(0)

# The query here for printing the full list only occurs in some
# circumstances; see the function docstring.
Expand All @@ -94,6 +101,12 @@ def do_suggest(inv, params):
print_results_table(with_index, with_score, results, params)


def print_divider(params):
"""Print a visual divider to break up sections of the CLI output."""
length = shutil.get_terminal_size().columns * 3 // 5
print_stderr("-" * length + "\n", params)


def print_stderr_result_count(params, results):
"""Report the count of found objects from the suggest search."""
if len(results) == 0:
Expand All @@ -104,7 +117,6 @@ def print_stderr_result_count(params, results):
),
params,
)
sys.exit(0)
else:
print_stderr(
(
Expand Down

0 comments on commit 648d3e8

Please sign in to comment.