in modular_cli/service/help_client.py [0:0]
def execute_command(self):
from modular_cli.service.decorators import (CommandResponse, JSON_VIEW,
TABLE_VIEW)
configure_args = {
'--module': (False, str),
'--detailed': (False, bool)
}
commands_meta = retrieve_commands_meta_content()
module, detailed = self.validate_params(configure_args=configure_args)
# reserved names
versions = {
'server': self._config.modular_api_version,
'client': __version__
}
if module:
if module == M3ADMIN_MODULE: # exception
name, version = M3ADMIN_MODULE, self._resolve_m3admin_version()
else:
name, version = next(
filter(lambda x: x[0] == module, self._resolve_modules_versions(commands_meta)),
(None, None)
)
if not version:
return CommandResponse(
message=f'Module: "{module}" is not installed', code=404,
)
versions = {name: version}
elif detailed:
versions.update(self._resolve_modules_versions(commands_meta))
m3admin = self._resolve_m3admin_version()
if m3admin:
versions[M3ADMIN_MODULE] = m3admin
# todo kludge because CommandResponse does not suit this command
# and it's better to make this little kludge instead of adding
# some version command-specific logic to CommandResponse
# and ResponseFormatter
ctx = click.get_current_context()
if ctx.params.get(JSON_VIEW):
click.echo(json.dumps({
n: {'version': v} for n, v in versions.items()
}, indent=4))
elif ctx.params.get(TABLE_VIEW):
return CommandResponse(
items=[{'name': n, 'version': v} for n, v in versions.items()],
table_title='Versions'
)
else:
click.echo(os.linesep.join(
f'{n.capitalize()}: {v}' for n, v in versions.items())
)
sys.exit(0)