Search in sources :

Example 1 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class GeogigCLI method executeInternal.

/**
     * Executes a command.
     * 
     * @param args
     * @throws exceptions thrown by the executed commands.
     */
private void executeInternal(String... args) throws ParameterException, CommandFailedException, IOException, CannotRunGeogigOperationException {
    JCommander mainCommander = newCommandParser();
    if (null == args || args.length == 0) {
        printShortCommandList(mainCommander);
        return;
    }
    {
        args = unalias(args);
        final String commandName = args[0];
        JCommander commandParser = mainCommander.getCommands().get(commandName);
        if (commandParser == null) {
            consoleReader.println(args[0] + " is not a geogig command. See geogig --help.");
            // check for similar commands
            Map<String, JCommander> candidates = spellCheck(mainCommander.getCommands(), commandName);
            if (!candidates.isEmpty()) {
                String msg = candidates.size() == 1 ? "Did you mean this?" : "Did you mean one of these?";
                consoleReader.println();
                consoleReader.println(msg);
                for (String name : candidates.keySet()) {
                    consoleReader.println("\t" + name);
                }
            }
            consoleReader.flush();
            throw new CommandFailedException(String.format("'%s' is not a command.", commandName));
        }
        Object object = commandParser.getObjects().get(0);
        if (object instanceof CLICommandExtension) {
            args = Arrays.asList(args).subList(1, args.length).toArray(new String[args.length - 1]);
            mainCommander = ((CLICommandExtension) object).getCommandParser();
            if (Lists.newArrayList(args).contains("--help")) {
                printUsage(mainCommander);
                return;
            }
        }
    }
    mainCommander.parse(args);
    final String parsedCommand = mainCommander.getParsedCommand();
    if (null == parsedCommand) {
        if (mainCommander.getObjects().size() == 0) {
            printUsage(mainCommander);
        } else if (mainCommander.getObjects().get(0) instanceof CLICommandExtension) {
            CLICommandExtension extension = (CLICommandExtension) mainCommander.getObjects().get(0);
            printUsage(extension.getCommandParser());
        } else {
            printUsage(mainCommander);
            throw new CommandFailedException();
        }
    } else {
        JCommander jCommander = mainCommander.getCommands().get(parsedCommand);
        List<Object> objects = jCommander.getObjects();
        CLICommand cliCommand = (CLICommand) objects.get(0);
        Class<? extends CLICommand> cmdClass = cliCommand.getClass();
        if (cliCommand instanceof AbstractCommand && ((AbstractCommand) cliCommand).help) {
            ((AbstractCommand) cliCommand).printUsage(this);
            getConsole().flush();
            return;
        }
        Hints hints = gatherHints(cmdClass);
        this.hints = hints;
        if (cmdClass.isAnnotationPresent(RequiresRepository.class) && cmdClass.getAnnotation(RequiresRepository.class).value()) {
            String workingDir;
            Platform platform = getPlatform();
            if (platform == null || platform.pwd() == null) {
                workingDir = "Couln't determine working directory.";
            } else {
                workingDir = platform.pwd().getAbsolutePath();
            }
            if (getGeogig() == null) {
                throw new CommandFailedException("Not in a geogig repository: " + workingDir);
            }
        }
        cliCommand.run(this);
        getConsole().flush();
    }
}
Also used : Hints(org.locationtech.geogig.repository.Hints) DefaultPlatform(org.locationtech.geogig.api.DefaultPlatform) Platform(org.locationtech.geogig.api.Platform) JCommander(com.beust.jcommander.JCommander) Map(java.util.Map) RequiresRepository(org.locationtech.geogig.cli.annotation.RequiresRepository)

Example 2 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class PGDescribeTest method setUpGeogig.

private void setUpGeogig(GeogigCLI cli) throws Exception {
    final File userhome = tempFolder.newFolder("mockUserHomeDir");
    final File workingDir = tempFolder.newFolder("mockWorkingDir");
    tempFolder.newFolder("mockWorkingDir/.geogig");
    final Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    when(platform.getUserHome()).thenReturn(userhome);
    cli.setPlatform(platform);
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Example 3 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class PGImportTest method setUpGeogig.

private void setUpGeogig(GeogigCLI cli) throws Exception {
    final File userhome = tempFolder.newFolder("mockUserHomeDir");
    final File workingDir = tempFolder.newFolder("mockWorkingDir");
    tempFolder.newFolder("mockWorkingDir/.geogig");
    final Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    when(platform.getUserHome()).thenReturn(userhome);
    cli.setPlatform(platform);
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Example 4 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class PGListTest method setUpGeogig.

private void setUpGeogig(GeogigCLI cli) throws Exception {
    final File userhome = tempFolder.newFolder("mockUserHomeDir");
    final File workingDir = tempFolder.newFolder("mockWorkingDir");
    tempFolder.newFolder("mockWorkingDir/.geogig");
    final Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    when(platform.getUserHome()).thenReturn(userhome);
    cli.setPlatform(platform);
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Example 5 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class SQLServerImportTest method setUpGeogig.

private void setUpGeogig(GeogigCLI cli) throws Exception {
    final File userhome = tempFolder.newFolder("mockUserHomeDir");
    final File workingDir = tempFolder.newFolder("mockWorkingDir");
    tempFolder.newFolder("mockWorkingDir/.geogig");
    final Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    when(platform.getUserHome()).thenReturn(userhome);
    cli.setPlatform(platform);
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Aggregations

Platform (org.locationtech.geogig.api.Platform)41 File (java.io.File)27 TestPlatform (org.locationtech.geogig.api.TestPlatform)10 Before (org.junit.Before)7 Context (org.locationtech.geogig.api.Context)7 GeogigModule (org.locationtech.geogig.di.GeogigModule)6 GeoGIG (org.locationtech.geogig.api.GeoGIG)5 ObjectId (org.locationtech.geogig.api.ObjectId)5 Repository (org.locationtech.geogig.repository.Repository)5 IOException (java.io.IOException)4 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)4 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)4 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)3 DefaultPlatform (org.locationtech.geogig.api.DefaultPlatform)3 MemoryModule (org.locationtech.geogig.api.MemoryModule)3 RevCommit (org.locationtech.geogig.api.RevCommit)3 RevTree (org.locationtech.geogig.api.RevTree)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 UnsupportedTerminal (jline.UnsupportedTerminal)2