use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class SQLServerDescribeTest method testDescribeException.
@Test
public void testDescribeException() throws Exception {
ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
GeogigCLI mockCli = spy(new GeogigCLI(consoleReader));
setUpGeogig(mockCli);
when(mockCli.getConsole()).thenThrow(new MockitoException("Exception"));
SQLServerDescribe describeCommand = new SQLServerDescribe();
describeCommand.table = "table1";
describeCommand.dataStoreFactory = TestHelper.createTestFactory();
exception.expect(MockitoException.class);
describeCommand.run(mockCli);
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class PGListTest method testListException.
@Test
public void testListException() throws Exception {
ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
GeogigCLI mockCli = spy(new GeogigCLI(consoleReader));
setUpGeogig(mockCli);
when(mockCli.getConsole()).thenThrow(new MockitoException("Exception"));
PGList listCommand = new PGList();
listCommand.dataStoreFactory = TestHelper.createTestFactory();
exception.expect(MockitoException.class);
listCommand.run(mockCli);
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class Ls method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Strategy lsStrategy = Strategy.CHILDREN;
if (recursive) {
if (includeTrees) {
lsStrategy = Strategy.DEPTHFIRST;
} else if (onlyTrees) {
lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
} else {
lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
}
} else {
if (onlyTrees) {
lsStrategy = Strategy.TREES_ONLY;
}
}
Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
final ConsoleReader console = cli.getConsole();
if (!iter.hasNext()) {
if (ref == null) {
console.println("The working tree is empty");
} else {
console.println("The specified path is empty");
}
return;
}
int depth = 0;
if (ref == null) {
console.println("Root tree/");
} else {
console.println(ref + "/");
depth = ref.split("/").length - 1;
}
final int rootDepth = depth;
Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {
@Override
public CharSequence apply(NodeRef input) {
String path = input.path();
int depth = path.split("/").length - rootDepth;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < depth; i++) {
sb.append('\t');
}
sb.append(input.getNode().getName());
if (input.getType().equals(TYPE.TREE)) {
sb.append('/');
}
if (verbose) {
sb.append(' ').append(abbrev(input.getMetadataId())).append(' ').append(abbrev(input.objectId()));
}
return sb.toString();
}
private String abbrev(ObjectId oid) {
return abbrev == null ? oid.toString() : oid.toString().substring(0, abbrev.intValue());
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class Tag method runInternal.
/**
* Executes the commit command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter((message != null && !message.trim().isEmpty()) || nameAndCommit.isEmpty() || delete, "No tag message provided");
checkParameter(nameAndCommit.size() < 2 || (nameAndCommit.size() == 2 && !delete), "Too many parameters provided");
if (nameAndCommit.isEmpty()) {
// looks like an attempt to create a tag with a message but forgot the tag name
checkParameter(message == null, "A tag name must be provided");
listTags(cli);
return;
}
String name = nameAndCommit.get(0);
String commit = nameAndCommit.size() > 1 ? nameAndCommit.get(1) : Ref.HEAD;
ConsoleReader console = cli.getConsole();
final GeoGIG geogig = cli.getGeogig();
if (delete) {
geogig.command(TagRemoveOp.class).setName(name).call();
console.println("Deleted tag " + name);
} else {
Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit).call();
checkParameter(commitId.isPresent(), "Wrong reference: " + commit);
RevTag tag = geogig.command(TagCreateOp.class).setName(name).setMessage(message).setCommitId(commitId.get()).call();
console.println("Created tag " + name + " -> " + tag.getCommitId());
}
}
use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.
the class GlobalState method setupGeogig.
public static void setupGeogig() throws Exception {
assertNotNull(platform);
stdIn = new ByteArrayInputStream(new byte[0]);
stdOut = new ByteArrayOutputStream();
if (GlobalState.consoleReader != null) {
GlobalState.consoleReader.shutdown();
}
// GlobalState.consoleReader = new ConsoleReader(stdIn,
// new TeeOutputStream(stdOut, System.err), new UnsupportedTerminal());
GlobalState.consoleReader = new ConsoleReader(stdIn, stdOut, new UnsupportedTerminal());
ContextBuilder injectorBuilder = new CLITestContextBuilder(platform);
Context injector = injectorBuilder.build();
if (geogigCLI != null) {
geogigCLI.close();
}
geogigCLI = new GeogigCLI(GlobalState.consoleReader);
GlobalContextBuilder.builder = injectorBuilder;
Platform platform = injector.platform();
geogigCLI.setPlatform(platform);
geogigCLI.tryConfigureLogging();
}
Aggregations