-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --failure-level command line option to force non-zero exit code (fixes #1113) #1114
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.asciidoctor.jruby.cli; | ||
|
||
import com.beust.jcommander.IStringConverter; | ||
import org.asciidoctor.SafeMode; | ||
import org.asciidoctor.log.Severity; | ||
|
||
public class SeverityConverter implements IStringConverter<Severity> { | ||
|
||
@Override | ||
public Severity convert(String argument) { return Severity.valueOf(argument.toUpperCase()); } | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import org.asciidoctor.jruby.syntaxhighlighter.internal.SyntaxHighlighterRegistryExecutor; | ||
import org.asciidoctor.log.LogHandler; | ||
import org.asciidoctor.log.LogRecord; | ||
import org.asciidoctor.log.Severity; | ||
import org.asciidoctor.syntaxhighlighter.SyntaxHighlighterRegistry; | ||
import org.jruby.*; | ||
import org.jruby.exceptions.RaiseException; | ||
|
@@ -46,6 +47,8 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler { | |
|
||
private List<LogHandler> logHandlers = new ArrayList<>(); | ||
|
||
private Severity maxSeverity = Severity.DEBUG; | ||
|
||
public JRubyAsciidoctor() { | ||
this(createRubyRuntime(Collections.singletonMap(GEM_PATH, null), new ArrayList<>(), null)); | ||
processRegistrations(this); | ||
|
@@ -507,8 +510,15 @@ private RubyClass getExtensionGroupClass() { | |
|
||
@Override | ||
public void log(LogRecord logRecord) { | ||
if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) { | ||
this.maxSeverity = logRecord.getSeverity(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JRubyAsciidoctor can be used in a multithreaded way when embedded into other environments like Spring Boot apps or sth similar. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, moved this to MaxSeverityLogHandler under org.asciidoctor.jruby.cli package. |
||
} | ||
for (LogHandler logHandler : logHandlers) { | ||
logHandler.log(logRecord); | ||
} | ||
} | ||
|
||
public Severity getMaxSeverity() { | ||
return this.maxSeverity; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I pass an invalid option like
INFOX
I currently get a stacktrace back that does not show the currently supported options:What do you think about changing it so that you'll get just a message with the invalid value and all supported values like:
Nitpick: Could you please add newlines after the opening brace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - and it turns out JCommander has
EnumConverter
class which gets us this nice error message for free.