mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor(config): change bindings import alias
This commit is contained in:
parent
f07fe88824
commit
39e2676055
1 changed files with 23 additions and 23 deletions
|
@ -2,7 +2,7 @@ import 'dart:ffi';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'bindings/libgit2_bindings.dart';
|
import 'bindings/libgit2_bindings.dart';
|
||||||
import 'bindings/config.dart' as config;
|
import 'bindings/config.dart' as bindings;
|
||||||
import 'util.dart';
|
import 'util.dart';
|
||||||
|
|
||||||
/// [Config] provides management of global configuration options
|
/// [Config] provides management of global configuration options
|
||||||
|
@ -23,14 +23,14 @@ class Config {
|
||||||
|
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
try {
|
try {
|
||||||
configPointer = config.openDefault();
|
_configPointer = bindings.openDefault();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (File(path!).existsSync()) {
|
if (File(path!).existsSync()) {
|
||||||
configPointer = config.open(path!);
|
_configPointer = bindings.open(path!);
|
||||||
} else {
|
} else {
|
||||||
throw Exception('File not found');
|
throw Exception('File not found');
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,10 @@ class Config {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final systemPath = config.findSystem();
|
final systemPath = bindings.findSystem();
|
||||||
configPointer = config.open(systemPath);
|
_configPointer = bindings.open(systemPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
configPointer = nullptr;
|
_configPointer = nullptr;
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +70,10 @@ class Config {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final globalPath = config.findGlobal();
|
final globalPath = bindings.findGlobal();
|
||||||
configPointer = config.open(globalPath);
|
_configPointer = bindings.open(globalPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
configPointer = nullptr;
|
_configPointer = nullptr;
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,10 +89,10 @@ class Config {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final xdgPath = config.findXdg();
|
final xdgPath = bindings.findXdg();
|
||||||
configPointer = config.open(xdgPath);
|
_configPointer = bindings.open(xdgPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
configPointer = nullptr;
|
_configPointer = nullptr;
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,17 +103,17 @@ class Config {
|
||||||
String? path;
|
String? path;
|
||||||
|
|
||||||
/// Pointer to memory address for allocated config object.
|
/// Pointer to memory address for allocated config object.
|
||||||
late Pointer<Pointer<git_config>> configPointer;
|
late final Pointer<Pointer<git_config>> _configPointer;
|
||||||
|
|
||||||
/// Returns map of all the config variables and their values.
|
/// Returns map of all the config variables and their values.
|
||||||
Map<String, String> getEntries() {
|
Map<String, String> getEntries() {
|
||||||
return config.getEntries(configPointer.value);
|
return bindings.getEntries(_configPointer.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the value of config [variable].
|
/// Returns the value of config [variable].
|
||||||
String getValue(String variable) {
|
String getValue(String variable) {
|
||||||
try {
|
try {
|
||||||
return config.getValue(configPointer.value, variable);
|
return bindings.getValue(_configPointer.value, variable);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
@ -123,11 +123,11 @@ class Config {
|
||||||
void setValue(String variable, dynamic value) {
|
void setValue(String variable, dynamic value) {
|
||||||
try {
|
try {
|
||||||
if (value.runtimeType == bool) {
|
if (value.runtimeType == bool) {
|
||||||
config.setBool(configPointer.value, variable, value);
|
bindings.setBool(_configPointer.value, variable, value);
|
||||||
} else if (value.runtimeType == int) {
|
} else if (value.runtimeType == int) {
|
||||||
config.setInt(configPointer.value, variable, value);
|
bindings.setInt(_configPointer.value, variable, value);
|
||||||
} else {
|
} else {
|
||||||
config.setString(configPointer.value, variable, value);
|
bindings.setString(_configPointer.value, variable, value);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -140,7 +140,7 @@ class Config {
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void deleteEntry(String variable) {
|
void deleteEntry(String variable) {
|
||||||
try {
|
try {
|
||||||
config.deleteEntry(configPointer.value, variable);
|
bindings.deleteEntry(_configPointer.value, variable);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ class Config {
|
||||||
/// If [regexp] is present, then the iterator will only iterate over all
|
/// If [regexp] is present, then the iterator will only iterate over all
|
||||||
/// values which match the pattern.
|
/// values which match the pattern.
|
||||||
List<String> getMultivarValue(String variable, {String? regexp}) {
|
List<String> getMultivarValue(String variable, {String? regexp}) {
|
||||||
return config.getMultivarValue(configPointer.value, variable, regexp);
|
return bindings.getMultivarValue(_configPointer.value, variable, regexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [value] of a multivar [variable] in the config file with the
|
/// Sets the [value] of a multivar [variable] in the config file with the
|
||||||
|
@ -160,7 +160,7 @@ class Config {
|
||||||
/// The [regexp] is applied case-sensitively on the value.
|
/// The [regexp] is applied case-sensitively on the value.
|
||||||
/// Empty [regexp] sets [value] for all values of a multivar [variable].
|
/// Empty [regexp] sets [value] for all values of a multivar [variable].
|
||||||
void setMultivarValue(String variable, String regexp, String value) {
|
void setMultivarValue(String variable, String regexp, String value) {
|
||||||
config.setMultivarValue(configPointer.value, variable, regexp, value);
|
bindings.setMultivarValue(_configPointer.value, variable, regexp, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes one or several values from a multivar [variable] in the config file
|
/// Deletes one or several values from a multivar [variable] in the config file
|
||||||
|
@ -169,11 +169,11 @@ class Config {
|
||||||
/// The [regexp] is applied case-sensitively on the value.
|
/// The [regexp] is applied case-sensitively on the value.
|
||||||
/// Empty [regexp] deletes all values of a multivar [variable].
|
/// Empty [regexp] deletes all values of a multivar [variable].
|
||||||
void deleteMultivar(String variable, String regexp) {
|
void deleteMultivar(String variable, String regexp) {
|
||||||
config.deleteMultivar(configPointer.value, variable, regexp);
|
bindings.deleteMultivar(_configPointer.value, variable, regexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Releases memory allocated for config object.
|
/// Releases memory allocated for config object.
|
||||||
void close() {
|
void close() {
|
||||||
calloc.free(configPointer);
|
calloc.free(_configPointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue