Search in sources :

Example 41 with Options

use of org.jline.builtins.Options in project karaf by apache.

the class Procedural method doThrow.

protected Object doThrow(CommandSession session, Process process, Object[] argv) throws ThrownException, HelpException, OptionException {
    String[] usage = { "throw -  throw an exception", "Usage: throw [ message [ cause ] ]", "       throw exception", "       throw", "  -? --help                    Show help" };
    Options opt = parseOptions(session, usage, argv);
    if (opt.argObjects().size() == 0) {
        Object exception = session.get("exception");
        if (exception instanceof Throwable)
            throw new ThrownException((Throwable) exception);
        else
            throw new ThrownException(new Exception());
    } else if (opt.argObjects().size() == 1 && opt.argObjects().get(0) instanceof Throwable) {
        throw new ThrownException((Throwable) opt.argObjects().get(0));
    } else {
        String message = opt.argObjects().get(0).toString();
        Throwable cause = null;
        if (opt.argObjects().size() > 1) {
            if (opt.argObjects().get(1) instanceof Throwable) {
                cause = (Throwable) opt.argObjects().get(1);
            }
        }
        throw new ThrownException(new Exception(message).initCause(cause));
    }
}
Also used : Options(org.jline.builtins.Options)

Aggregations

Options (org.jline.builtins.Options)41 AttributedString (org.jline.utils.AttributedString)16 Function (org.apache.felix.service.command.Function)15 ArrayList (java.util.ArrayList)14 Process (org.apache.felix.service.command.Process)12 InputStreamReader (java.io.InputStreamReader)10 BufferedReader (java.io.BufferedReader)9 InputStream (java.io.InputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FilterInputStream (java.io.FilterInputStream)8 PrintStream (java.io.PrintStream)8 Path (java.nio.file.Path)8 CommandSession (org.apache.felix.service.command.CommandSession)8 AttributedStringBuilder (org.jline.utils.AttributedStringBuilder)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOException (java.io.IOException)7 HashSet (java.util.HashSet)7 Reader (java.io.Reader)6 TreeMap (java.util.TreeMap)6 Closeable (java.io.Closeable)5