Skip to content

Commit d15cf93

Browse files
committed
Merge pull request #2197 from svisser/patch-1
Updated show command to return a status code
2 parents 0f5b325 + bea6c7d commit d15cf93

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pip/commands/show.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55

66
from pip.basecommand import Command
7+
from pip.status_codes import SUCCESS, ERROR
78
from pip._vendor import pkg_resources
89

910

@@ -31,11 +32,13 @@ def __init__(self, *args, **kw):
3132
def run(self, options, args):
3233
if not args:
3334
logger.warning('ERROR: Please provide a package name or names.')
34-
return
35+
return ERROR
3536
query = args
3637

3738
results = search_packages_info(query)
38-
print_results(results, options.files)
39+
if not print_results(results, options.files):
40+
return ERROR
41+
return SUCCESS
3942

4043

4144
def search_packages_info(query):
@@ -79,7 +82,9 @@ def print_results(distributions, list_all_files):
7982
"""
8083
Print the informations from installed distributions found.
8184
"""
85+
results_printed = False
8286
for dist in distributions:
87+
results_printed = True
8388
logger.info("---")
8489
logger.info("Name: %s" % dist['name'])
8590
logger.info("Version: %s" % dist['version'])
@@ -92,3 +97,4 @@ def print_results(distributions, list_all_files):
9297
logger.info(" %s" % line.strip())
9398
else:
9499
logger.info("Cannot locate installed-files.txt")
100+
return results_printed

tests/functional/test_show.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_missing_argument(script):
6464
"""
6565
Test show command with no arguments.
6666
"""
67-
result = script.pip('show')
67+
result = script.pip('show', expect_error=True)
6868
assert 'ERROR: Please provide a package name or names.' in result.stdout
6969

7070

0 commit comments

Comments
 (0)