Search in sources :

Example 1 with Hints

use of org.locationtech.geogig.repository.Hints 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 Hints

use of org.locationtech.geogig.repository.Hints in project GeoGig by boundlessgeo.

the class GeogigCLI method gatherHints.

private Hints gatherHints(Class<? extends CLICommand> cmdClass) {
    Hints hints = new Hints();
    checkAnnotationHint(cmdClass, ReadOnly.class, Hints.OBJECTS_READ_ONLY, hints);
    checkAnnotationHint(cmdClass, ReadOnly.class, Hints.STAGING_READ_ONLY, hints);
    checkAnnotationHint(cmdClass, ObjectDatabaseReadOnly.class, Hints.OBJECTS_READ_ONLY, hints);
    checkAnnotationHint(cmdClass, StagingDatabaseReadOnly.class, Hints.STAGING_READ_ONLY, hints);
    checkAnnotationHint(cmdClass, RemotesReadOnly.class, Hints.REMOTES_READ_ONLY, hints);
    return hints;
}
Also used : Hints(org.locationtech.geogig.repository.Hints)

Example 3 with Hints

use of org.locationtech.geogig.repository.Hints in project GeoGig by boundlessgeo.

the class SendPack method getRemoteRepo.

/**
     * @param remote the remote to get
     * @return an interface for the remote repository
     */
@VisibleForTesting
public Optional<IRemoteRepo> getRemoteRepo(Remote remote) {
    Hints remoteHints = new Hints();
    remoteHints.set(Hints.REMOTES_READ_ONLY, Boolean.FALSE);
    Repository localRepository = repository();
    DeduplicationService deduplicationService = context.deduplicationService();
    return RemoteUtils.newRemote(GlobalContextBuilder.builder.build(remoteHints), remote, localRepository, deduplicationService);
}
Also used : Repository(org.locationtech.geogig.repository.Repository) Hints(org.locationtech.geogig.repository.Hints) DeduplicationService(org.locationtech.geogig.storage.DeduplicationService) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with Hints

use of org.locationtech.geogig.repository.Hints in project GeoGig by boundlessgeo.

the class JEGraphDatabaseV1StressTest method createDatabase.

@Override
protected GraphDatabase createDatabase(TestPlatform platform) {
    File root = platform.pwd();
    Preconditions.checkState(new File(root, ".geogig").exists());
    envProvider = new EnvironmentBuilder(platform);
    ConfigDatabase configDB = new IniFileConfigDatabase(platform);
    return new JEGraphDatabase_v0_1(configDB, envProvider, new Hints());
}
Also used : Hints(org.locationtech.geogig.repository.Hints) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) IniFileConfigDatabase(org.locationtech.geogig.storage.fs.IniFileConfigDatabase) File(java.io.File) IniFileConfigDatabase(org.locationtech.geogig.storage.fs.IniFileConfigDatabase)

Example 5 with Hints

use of org.locationtech.geogig.repository.Hints in project GeoGig by boundlessgeo.

the class JEGraphDatabaseV1Test method createDatabase.

@Override
protected GraphDatabase createDatabase(Platform platform) throws Exception {
    File root = platform.pwd();
    Preconditions.checkState(new File(root, ".geogig").exists());
    envProvider = new EnvironmentBuilder(platform);
    ConfigDatabase configDB = new IniFileConfigDatabase(platform);
    return new JEGraphDatabase_v0_1(configDB, envProvider, new Hints());
}
Also used : Hints(org.locationtech.geogig.repository.Hints) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) IniFileConfigDatabase(org.locationtech.geogig.storage.fs.IniFileConfigDatabase) File(java.io.File) IniFileConfigDatabase(org.locationtech.geogig.storage.fs.IniFileConfigDatabase)

Aggregations

Hints (org.locationtech.geogig.repository.Hints)8 File (java.io.File)5 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)4 IniFileConfigDatabase (org.locationtech.geogig.storage.fs.IniFileConfigDatabase)4 JCommander (com.beust.jcommander.JCommander)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Map (java.util.Map)1 Before (org.junit.Before)1 DefaultPlatform (org.locationtech.geogig.api.DefaultPlatform)1 Platform (org.locationtech.geogig.api.Platform)1 TestPlatform (org.locationtech.geogig.api.TestPlatform)1 RequiresRepository (org.locationtech.geogig.cli.annotation.RequiresRepository)1 Repository (org.locationtech.geogig.repository.Repository)1 DeduplicationService (org.locationtech.geogig.storage.DeduplicationService)1