Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions shell/src/main/java/org/apache/accumulo/shell/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ public class Shell extends ShellOptions implements KeywordExecutable {
private PrintWriter writer = null;
private boolean masking = false;

public Shell() throws IOException {
this(new ConsoleReader(), new PrintWriter(new OutputStreamWriter(System.out, Charset.forName(System.getProperty("jline.WindowsTerminal.output.encoding",
System.getProperty("file.encoding"))))));
}
// no arg constructor should do minimal work since its used in Main ServiceLoader
public Shell() {}

public Shell(ConsoleReader reader, PrintWriter writer) {
super();
Expand All @@ -246,7 +244,12 @@ public Shell(ConsoleReader reader, PrintWriter writer) {
*
* @return true if the shell was successfully configured, false otherwise.
*/
public boolean config(String... args) {
public boolean config(String... args) throws IOException {
if (this.reader == null)
this.reader = new ConsoleReader();
if (this.writer == null)
this.writer = new PrintWriter(new OutputStreamWriter(System.out, Charset.forName(System.getProperty("jline.WindowsTerminal.output.encoding",
System.getProperty("file.encoding")))));
ShellOptionsJC options = new ShellOptionsJC();
JCommander jc = new JCommander();

Expand Down Expand Up @@ -583,7 +586,8 @@ public void execute(final String[] args) throws IOException {
}

public static void main(String args[]) throws IOException {
new Shell().execute(args);
new Shell(new ConsoleReader(), new PrintWriter(new OutputStreamWriter(System.out, Charset.forName(System.getProperty(
"jline.WindowsTerminal.output.encoding", System.getProperty("file.encoding")))))).execute(args);
}

public int start() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public MockShell(InputStream in, OutputStream out) throws IOException {
}

@Override
public boolean config(String... args) {
public boolean config(String... args) throws IOException {
// If configuring the shell failed, fail quickly
if (!super.config(args)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.file.Files;
Expand Down Expand Up @@ -91,30 +92,30 @@ public String[] args(String... args) {
}

@Test
public void testHelp() {
public void testHelp() throws IOException {
assertFalse(shell.config(args("--help")));
assertTrue("Did not print usage", output.get().startsWith("Usage"));
}

@Test
public void testBadArg() {
public void testBadArg() throws IOException {
assertFalse(shell.config(args("--bogus")));
assertTrue("Did not print usage", output.get().startsWith("Usage"));
}

@Test
public void testTokenWithoutOptions() {
public void testTokenWithoutOptions() throws IOException {
assertFalse(shell.config(args("--fake", "-tc", PasswordToken.class.getName())));
assertFalse(output.get().contains(ParameterException.class.getName()));
}

@Test
public void testTokenAndOption() {
public void testTokenAndOption() throws IOException {
assertTrue(shell.config(args("--fake", "-tc", PasswordToken.class.getName(), "-u", "foo", "-l", "password=foo")));
}

@Test
public void testTokenAndOptionAndPassword() {
public void testTokenAndOptionAndPassword() throws IOException {
assertFalse(shell.config(args("--fake", "-tc", PasswordToken.class.getName(), "-l", "password=foo", "-p", "bar")));
assertTrue(output.get().contains(ParameterException.class.getName()));
}
Expand Down