Skip to content

Commit bd5783c

Browse files
committed
default for list will show all unique container:tag
unless the user adds --short, in which case the tags will again be combined into a single list alongside the container name. Signed-off-by: vsoch <[email protected]>
1 parent 123c821 commit bd5783c

File tree

7 files changed

+53
-8
lines changed

7 files changed

+53
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The versions coincide with releases on pip. Only major versions will be released
1717
- adding namespaces to make module install, show, inspect easier (0.0.24)
1818
- added support for env section to render to bound environment file
1919
- added support for container features like gpu
20+
- list defaults to showing modules/tags one per line, unless --short used
2021
- container url does not render in docs (0.0.23)
2122
- addition of tcl modules, removal of un-needed database (0.0.22)
2223
- first update of all containers, and bugfix to pull (0.0.21)

docs/getting_started/user-guide.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,39 @@ List
481481
----
482482

483483
Once a module is installed, you can use list to show installed modules (and versions).
484+
The default list will flatten out module names and tags into a single list
485+
to make it easy to copy paste:
484486

485487
.. code-block:: console
486488
487489
$ shpc list
488-
python: 3.9.2-alpine, 3.9.2-slim
490+
biocontainers/samtools:v1.9-4-deb_cv1
491+
python:3.9.2-alpine
492+
python:3.9.5-alpine
493+
python:3.9.2-slim
494+
dinosaur:fork
495+
vanessa/salad:latest
496+
salad:latest
497+
ghcr.io/autamus/prodigal:latest
498+
ghcr.io/autamus/samtools:latest
499+
ghcr.io/autamus/clingo:5.5.0
500+
501+
502+
However, if you want a shorter version that shows multiple tags alongside
503+
each unique module name, just add ``--short``:
504+
505+
.. code-block:: console
506+
507+
$ shpc list --short
508+
509+
biocontainers/samtools: v1.9-4-deb_cv1
510+
python: 3.9.5-alpine, 3.9.2-alpine, 3.9.2-slim
511+
dinosaur: fork
512+
vanessa/salad: latest
513+
salad: latest
514+
ghcr.io/autamus/prodigal: latest
515+
ghcr.io/autamus/samtools: latest
516+
ghcr.io/autamus/clingo: 5.5.0
489517
490518
491519
Inspect

registry/vanessa/salad/container.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ tags:
88
latest: sha256:e8302da47e3200915c1d3a9406d9446f04da7244e4995b7135afd2b79d4f63db
99
aliases:
1010
salad: /code/salad
11-
features:
12-
gpu: true
1311
env:
1412
maintainer: vsoch

shpc/client/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ def get_parser():
8484
"--names-only", help="omit versions", default=False, action="store_true"
8585
)
8686

87+
listing.add_argument(
88+
"--short",
89+
help="multiple tags per line for shorter length output.",
90+
default=False,
91+
action="store_true",
92+
)
93+
8794
# List local containers and collections
8895
inspect = subparsers.add_parser(
8996
"inspect", help="inspect an installed module image."

shpc/client/listing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ def main(args, parser, extra, subparser):
1414
container_tech=args.container_tech,
1515
)
1616

17-
cli.list(args.pattern, args.names_only)
17+
cli.list(args.pattern, args.names_only, short=args.short)

shpc/main/modules.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,17 @@ def get(self, module_name):
187187
logger.exit("Found more than one sif in module folder.")
188188
return sif[0]
189189

190-
def list(self, pattern=None, names_only=False, out=None):
190+
def list(self, pattern=None, names_only=False, out=None, short=False):
191191
"""
192192
List installed modules.
193193
"""
194194
self._list_modules(
195-
self.settings.module_base, self.modulefile, pattern, names_only, out
195+
self.settings.module_base,
196+
self.modulefile,
197+
pattern,
198+
names_only,
199+
out,
200+
short=short,
196201
)
197202

198203
def docgen(self, module_name, out=None):
@@ -240,7 +245,9 @@ def inspect(self, module_name):
240245
sif = self.get(module_name)
241246
return self._container.inspect(sif[0])
242247

243-
def _list_modules(self, base, filename, pattern=None, names_only=False, out=None):
248+
def _list_modules(
249+
self, base, filename, pattern=None, names_only=False, out=None, short=False
250+
):
244251
"""A shared function to list modules or registry entries."""
245252
out = out or sys.stdout
246253
modules = self._get_module_lookup(base, filename, pattern)
@@ -253,8 +260,11 @@ def _list_modules(self, base, filename, pattern=None, names_only=False, out=None
253260
for module_name, versions in modules.items():
254261
if names_only:
255262
out.write("%s\n" % module_name)
256-
else:
263+
elif short:
257264
out.write("%s: %s\n" % (module_name.rjust(30), ", ".join(versions)))
265+
else:
266+
for version in versions:
267+
out.write("%s:%s\n" % (module_name.rjust(30), version))
258268

259269
def _get_module_lookup(self, base, filename, pattern=None):
260270
"""A shared function to get a lookup of installed modules or registry entries"""

shpc/tests/test_client.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ echo
6868
echo "#### Testing list "
6969
runTest 0 $output shpc --settings-file $settings list --help
7070
runTest 0 $output shpc --settings-file $settings list
71+
runTest 0 $output shpc --settings-file $settings list --short
7172
runTest 0 $output shpc --settings-file $settings list salad
7273

7374
echo

0 commit comments

Comments
 (0)