Search in sources :

Example 1 with IExceptionHandler2

use of picocli.CommandLine.IExceptionHandler2 in project ozone by apache.

the class TestGenerateOzoneRequiredConfigurations method execute.

private void execute(String[] args, String msg) throws UnsupportedEncodingException {
    List<String> arguments = new ArrayList(Arrays.asList(args));
    LOG.info("Executing shell command with args {}", arguments);
    CommandLine cmd = genconfTool.getCmd();
    IExceptionHandler2<List<Object>> exceptionHandler = new IExceptionHandler2<List<Object>>() {

        @Override
        public List<Object> handleParseException(ParameterException ex, String[] args) {
            throw ex;
        }

        @Override
        public List<Object> handleExecutionException(ExecutionException ex, ParseResult parseResult) {
            throw ex;
        }
    };
    cmd.parseWithHandlers(new CommandLine.RunLast(), exceptionHandler, args);
    Assert.assertTrue(out.toString(DEFAULT_ENCODING).contains(msg));
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ParameterException(picocli.CommandLine.ParameterException) IExceptionHandler2(picocli.CommandLine.IExceptionHandler2) ExecutionException(picocli.CommandLine.ExecutionException)

Example 2 with IExceptionHandler2

use of picocli.CommandLine.IExceptionHandler2 in project ozone by apache.

the class TestGenerateOzoneRequiredConfigurations method executeWithException.

private void executeWithException(String[] args, String msg) {
    List<String> arguments = new ArrayList(Arrays.asList(args));
    LOG.info("Executing shell command with args {}", arguments);
    CommandLine cmd = genconfTool.getCmd();
    IExceptionHandler2<List<Object>> exceptionHandler = new IExceptionHandler2<List<Object>>() {

        @Override
        public List<Object> handleParseException(ParameterException ex, String[] args) {
            throw ex;
        }

        @Override
        public List<Object> handleExecutionException(ExecutionException ex, ParseResult parseResult) {
            throw ex;
        }
    };
    try {
        cmd.parseWithHandlers(new CommandLine.RunLast(), exceptionHandler, args);
    } catch (Exception ex) {
        Assert.assertTrue("Expected " + msg + ", but got: " + ex.getMessage(), ex.getMessage().contains(msg));
    }
}
Also used : ParseResult(picocli.CommandLine.ParseResult) ArrayList(java.util.ArrayList) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandLine(picocli.CommandLine) ArrayList(java.util.ArrayList) List(java.util.List) ParameterException(picocli.CommandLine.ParameterException) IExceptionHandler2(picocli.CommandLine.IExceptionHandler2) ExecutionException(picocli.CommandLine.ExecutionException)

Example 3 with IExceptionHandler2

use of picocli.CommandLine.IExceptionHandler2 in project ozone by apache.

the class TestOzoneDatanodeShell method executeDatanode.

private void executeDatanode(HddsDatanodeService hdds, String[] args) {
    LOG.info("Executing datanode command with args {}", Arrays.asList(args));
    CommandLine cmd = hdds.getCmd();
    IExceptionHandler2<List<Object>> exceptionHandler = new IExceptionHandler2<List<Object>>() {

        @Override
        public List<Object> handleParseException(ParameterException ex, String[] args) {
            throw ex;
        }

        @Override
        public List<Object> handleExecutionException(ExecutionException ex, ParseResult parseResult) {
            throw ex;
        }
    };
    cmd.parseWithHandlers(new RunLast(), exceptionHandler, args);
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) RunLast(picocli.CommandLine.RunLast) List(java.util.List) ParameterException(picocli.CommandLine.ParameterException) IExceptionHandler2(picocli.CommandLine.IExceptionHandler2) ExecutionException(picocli.CommandLine.ExecutionException)

Example 4 with IExceptionHandler2

use of picocli.CommandLine.IExceptionHandler2 in project ozone by apache.

the class TestOzoneShellHA method execute.

private void execute(GenericCli shell, String[] args) {
    LOG.info("Executing OzoneShell command with args {}", Arrays.asList(args));
    CommandLine cmd = shell.getCmd();
    IExceptionHandler2<List<Object>> exceptionHandler = new IExceptionHandler2<List<Object>>() {

        @Override
        public List<Object> handleParseException(ParameterException ex, String[] args) {
            throw ex;
        }

        @Override
        public List<Object> handleExecutionException(ExecutionException ex, ParseResult parseRes) {
            throw ex;
        }
    };
    // Since there is no elegant way to pass Ozone config to the shell,
    // the idea is to use 'set' to place those OM HA configs.
    String[] argsWithHAConf = getHASetConfStrings(args);
    cmd.parseWithHandlers(new RunLast(), exceptionHandler, argsWithHAConf);
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) RunLast(picocli.CommandLine.RunLast) List(java.util.List) ArrayList(java.util.ArrayList) ParameterException(picocli.CommandLine.ParameterException) IExceptionHandler2(picocli.CommandLine.IExceptionHandler2) ExecutionException(picocli.CommandLine.ExecutionException)

Example 5 with IExceptionHandler2

use of picocli.CommandLine.IExceptionHandler2 in project ozone by apache.

the class TestAuditParser method execute.

private static void execute(String[] args, String msg) {
    List<String> arguments = new ArrayList(Arrays.asList(args));
    LOG.info("Executing shell command with args {}", arguments);
    CommandLine cmd = parserTool.getCmd();
    IExceptionHandler2<List<Object>> exceptionHandler = new IExceptionHandler2<List<Object>>() {

        @Override
        public List<Object> handleParseException(ParameterException ex, String[] args) {
            throw ex;
        }

        @Override
        public List<Object> handleExecutionException(ExecutionException ex, ParseResult parseResult) {
            throw ex;
        }
    };
    cmd.parseWithHandlers(new CommandLine.RunLast(), exceptionHandler, args);
    try {
        Assert.assertTrue(OUT.toString(DEFAULT_CODING).contains(msg));
    } catch (UnsupportedEncodingException ignored) {
    }
}
Also used : ParseResult(picocli.CommandLine.ParseResult) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandLine(picocli.CommandLine) ArrayList(java.util.ArrayList) List(java.util.List) ParameterException(picocli.CommandLine.ParameterException) IExceptionHandler2(picocli.CommandLine.IExceptionHandler2) ExecutionException(picocli.CommandLine.ExecutionException)

Aggregations

List (java.util.List)5 CommandLine (picocli.CommandLine)5 ExecutionException (picocli.CommandLine.ExecutionException)5 IExceptionHandler2 (picocli.CommandLine.IExceptionHandler2)5 ParameterException (picocli.CommandLine.ParameterException)5 ParseResult (picocli.CommandLine.ParseResult)5 ArrayList (java.util.ArrayList)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 RunLast (picocli.CommandLine.RunLast)2 IOException (java.io.IOException)1