Add unregistered CommandViewer

This commit is contained in:
Mihail Shinder 2021-11-19 10:34:00 +02:00
parent d6e42f3307
commit 7ac3ae990f
No known key found for this signature in database
GPG Key ID: C89443B0B525978E

View File

@ -258,6 +258,26 @@ except ImportError:
else: else:
register(IPythonViewer) register(IPythonViewer)
class CommandViewer(Viewer):
"""
The viewer that use commands.
Should be suitable for any OS
"""
def get_command(self, file, **options):
"""
Substitute ``{}`` specifiers in ``command``
:param options: kwargs that should have 'command' in it
"""
if not "command" in options:
raise TypeError("CommandViewer missing required keyword-only argument 'command'")
command = options["command"]
if not isinstance(command, str):
raise TypeError(f"'command' must be 'str' not '{type(command)}'")
values = {'file': file, **options}
return command.format(values)
if __name__ == "__main__": if __name__ == "__main__":