[module info] exit with 1 if no valid modules was specified (RhBug:1623535)

This commit is contained in:
Martin Hatina 2018-09-06 09:57:38 +02:00
parent a452086a78
commit 4789d9aa09
2 changed files with 7 additions and 2 deletions

View File

@ -19,6 +19,7 @@
from __future__ import print_function
import dnf
from dnf.cli import commands, CliError
from dnf.i18n import _
from dnf.module.exceptions import NoModuleException, EnableMultipleStreamsException
@ -68,9 +69,9 @@ class ModuleCommand(commands.Command):
demands.sack_activation = True
def run_on_module(self):
errors = []
for spec in self.opts.module_spec:
try:
print()
if self.opts.verbose:
print(self.base.repo_module_dict.get_full_info(spec))
elif self.opts.profile:
@ -78,7 +79,10 @@ class ModuleCommand(commands.Command):
else:
print(self.base.repo_module_dict.get_info(spec))
except NoModuleException as e:
logger.info(e)
errors.append(e.module_spec)
if errors and len(errors) == len(self.opts.module_spec):
raise dnf.exceptions.Error("No such modules: {}".format(", ".join(errors)))
class EnableSubCommand(SubCommand):

View File

@ -35,6 +35,7 @@ class MissingYamlException(dnf.exceptions.Error):
class NoModuleException(dnf.exceptions.Error):
def __init__(self, module_spec):
self.module_spec = module_spec
value = "No such module: {}".format(module_spec)
super(NoModuleException, self).__init__(value)