Skip to content

Commit

Permalink
FORGE-2336: Showing Warning and Info messages on execute in shell
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed May 21, 2015
1 parent a3a24fb commit f3f832f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Expand Up @@ -21,7 +21,6 @@
import org.jboss.forge.addon.shell.ui.ShellContext;
import org.jboss.forge.addon.ui.context.UISelection;
import org.jboss.forge.addon.ui.output.UIMessage;
import org.jboss.forge.addon.ui.output.UIMessage.Severity;
import org.jboss.forge.addon.ui.output.UIOutput;
import org.jboss.forge.addon.ui.result.CompositeResult;
import org.jboss.forge.addon.ui.result.Failed;
Expand Down Expand Up @@ -74,7 +73,24 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
}
if (!failure)
{
if (interaction.getController().isValid())
UIOutput output = shell.getOutput();
for (UIMessage message : interaction.getController().validate())
{
switch (message.getSeverity())
{
case ERROR:
failure = true;
output.error(output.err(), message.getDescription());
break;
case INFO:
output.info(output.out(), message.getDescription());
break;
case WARN:
output.warn(output.out(), message.getDescription());
break;
}
}
if (!failure)
{
Result commandResult = null;
try
Expand All @@ -97,19 +113,6 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
}
}
}
else
{
List<UIMessage> messages = interaction.getController().validate();
UIOutput output = shell.getOutput();
for (UIMessage message : messages)
{
if (message.getSeverity() == Severity.ERROR)
{
failure = true;
output.error(output.err(), message.getDescription());
}
}
}
}
return failure ? CommandResult.FAILURE : CommandResult.SUCCESS;
}
Expand Down
Expand Up @@ -9,6 +9,7 @@

import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.output.UIMessage;
import org.jboss.forge.furnace.util.Assert;

/**
*
Expand All @@ -22,6 +23,7 @@ public class UIMessageImpl implements UIMessage

public UIMessageImpl(Severity severity, String description, InputComponent<?, ?> inputComponent)
{
Assert.notNull(severity, "Severity should never be null");
this.description = description;
this.severity = severity;
this.inputComponent = inputComponent;
Expand Down

0 comments on commit f3f832f

Please sign in to comment.