mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
feat(config): add ability to get values of all variables
This commit is contained in:
parent
f6b8cc7005
commit
2d1c026e73
4 changed files with 22 additions and 19 deletions
|
@ -182,12 +182,12 @@ void setString(Pointer<git_config> cfg, String name, String value) {
|
|||
}
|
||||
|
||||
/// Iterate over all the config variables.
|
||||
Map<String, dynamic> getVariables(Pointer<git_config> cfg) {
|
||||
Map<String, String> getEntries(Pointer<git_config> cfg) {
|
||||
final iterator = calloc<Pointer<git_config_iterator>>();
|
||||
final entry = calloc<Pointer<git_config_entry>>();
|
||||
libgit2.git_config_iterator_new(iterator, cfg);
|
||||
var error = 0;
|
||||
final entries = <String, dynamic>{};
|
||||
final entries = <String, String>{};
|
||||
|
||||
while (error != -31) {
|
||||
error = libgit2.git_config_next(entry, iterator.value);
|
||||
|
|
|
@ -39,8 +39,6 @@ class Config {
|
|||
}
|
||||
}
|
||||
|
||||
variables = config.getVariables(configPointer.value);
|
||||
|
||||
libgit2.git_libgit2_shutdown();
|
||||
}
|
||||
|
||||
|
@ -55,7 +53,6 @@ class Config {
|
|||
try {
|
||||
final systemPath = config.findSystem();
|
||||
configPointer = config.open(systemPath);
|
||||
variables = config.getVariables(configPointer.value);
|
||||
} catch (e) {
|
||||
configPointer = nullptr;
|
||||
rethrow;
|
||||
|
@ -75,7 +72,6 @@ class Config {
|
|||
try {
|
||||
final globalPath = config.findGlobal();
|
||||
configPointer = config.open(globalPath);
|
||||
variables = config.getVariables(configPointer.value);
|
||||
} catch (e) {
|
||||
configPointer = nullptr;
|
||||
rethrow;
|
||||
|
@ -95,7 +91,6 @@ class Config {
|
|||
try {
|
||||
final xdgPath = config.findXdg();
|
||||
configPointer = config.open(xdgPath);
|
||||
variables = config.getVariables(configPointer.value);
|
||||
} catch (e) {
|
||||
configPointer = nullptr;
|
||||
rethrow;
|
||||
|
@ -110,8 +105,10 @@ class Config {
|
|||
/// Pointer to memory address for allocated config object.
|
||||
late Pointer<Pointer<git_config>> configPointer;
|
||||
|
||||
/// Map of key/value entries from config file.
|
||||
Map<String, dynamic> variables = {};
|
||||
/// Returns map of all the config variables and their values
|
||||
Map<String, String> getEntries() {
|
||||
return config.getEntries(configPointer.value);
|
||||
}
|
||||
|
||||
/// Returns the value of config [variable]
|
||||
String getValue(String variable) {
|
||||
|
@ -132,7 +129,6 @@ class Config {
|
|||
} else {
|
||||
config.setString(configPointer.value, variable, value);
|
||||
}
|
||||
variables = config.getVariables(configPointer.value);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
@ -145,7 +141,6 @@ class Config {
|
|||
void deleteVariable(String key) {
|
||||
try {
|
||||
config.deleteVariable(configPointer.value, key);
|
||||
variables = config.getVariables(configPointer.value);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue