/
ConfigGet.java
76 lines (66 loc) · 2.43 KB
/
ConfigGet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Copyright (c) 2013-2016 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Victor Olaya (Boundless) - initial implementation
*/
package org.locationtech.geogig.porcelain;
import java.util.Map;
import java.util.Optional;
import org.locationtech.geogig.di.CanRunDuringConflict;
import org.locationtech.geogig.porcelain.ConfigOp.ConfigAction;
import org.locationtech.geogig.porcelain.ConfigOp.ConfigScope;
import org.locationtech.geogig.repository.impl.AbstractGeoGigOp;
import org.locationtech.geogig.storage.ConfigException;
/**
* Get a repository or global options
* <p>
* This is just a shortcut for using ConfigOp in the case of wanting to retrieve a single config
* value
* <p>
*
* @see ConfigOp
*/
@CanRunDuringConflict
public class ConfigGet extends AbstractGeoGigOp<Optional<String>> {
private boolean global;
private String name;
/**
* Executes the config command with the specified options.
*
* @return Optional<String> if querying for a value, empty Optional if no matching name was
* found.
* @throws ConfigException if an error is encountered. More specific information can be found in
* the exception's statusCode.
*/
protected @Override Optional<String> _call() {
ConfigScope scope = global ? ConfigScope.GLOBAL : ConfigScope.LOCAL;
Optional<Map<String, String>> configGetResult = command(ConfigOp.class)
.setAction(ConfigAction.CONFIG_GET).setName(name).setScope(scope).call();
if (configGetResult.isPresent()) {
return Optional.of(configGetResult.get().get(name));
} else {
return Optional.empty();
}
}
/**
* @param global if true, config actions will be executed on the global configuration file. If
* false, then all actions will be done on the config file in the local repository.
* @return {@code this}
*/
public ConfigGet setGlobal(boolean global) {
this.global = global;
return this;
}
/**
* @param name the name of the variable to get
* @return {@code this}
*/
public ConfigGet setName(String name) {
this.name = name;
return this;
}
}