Skip to content

Commit

Permalink
Add options to control extension reporting output
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Dec 21, 2017
1 parent 890f9e8 commit 068d69d
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions asdf/commands/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Implementation of command for reporting information about installed extensions.
"""

import sys
from pkg_resources import iter_entry_points

from .main import Command
Expand All @@ -18,12 +19,24 @@ def setup_arguments(cls, subparsers):
"extensions", help="Show information about installed extensions",
description="""Reports information about installed ASDF extensions""")

parser.add_argument(
"-s", "--summary", action="store_true",
help="Display only the installed extensions themselves")
parser.add_argument(
"-t", "--tags-only", action="store_true",
help="Display tags from installed extensions, but no other information")

parser.set_defaults(func=cls.run)
return parser

@classmethod
def run(cls, args):
return find_extensions()
if args.summary and args.tags_only:
sys.stderr.write(
"ERROR: Options -s/--summary and -t/--tags-only are not compatible\n")
return 1

return find_extensions(args.summary, args.tags_only)


def _format_entry_point(ep):
Expand All @@ -40,17 +53,21 @@ def _tag_comparator(a, b):
return _format_type_name(a) < _format_type_name(b)


def find_extensions():

for ep in iter_entry_points(group='asdf_extensions'):
print(_format_entry_point(ep))
ext = ep.load()()
for typ in sorted(ext.types, key=lambda x: _format_type_name(x)):
if typ.name is not None:
print("- " + _format_type_name(typ))
def _print_extension_details(ext, tags_only):
for typ in sorted(ext.types, key=lambda x: _format_type_name(x)):
if typ.name is not None:
print("- " + _format_type_name(typ))
if not tags_only:
print(" implements: {}".format(typ.make_yaml_tag(typ.name)))
if typ.types:
print(" serializes:")
for name in typ.types:
print(" - {}".format(_format_type_name(name)))
print()


def find_extensions(summary, tags_only):
for ep in iter_entry_points(group='asdf_extensions'):
print(_format_entry_point(ep))
if not summary:
_print_extension_details(ep.load()(), tags_only)
print()

0 comments on commit 068d69d

Please sign in to comment.