mount method
Mounts the sidekick related globals, returns a function to unmount them and restore the previous globals
Implementation
Unmount mount({String? debugName}) {
final SidekickCommandRunner? oldRunner = _activeRunner;
final SidekickContextCache oldCache = internalSidekickContextCache;
_activeRunner = this;
final newCache = SidekickContextCache(debugName: debugName);
internalSidekickContextCache = newCache;
final Directory? oldWorkingDirectory = _entryWorkingDirectory;
_entryWorkingDirectory = Directory.current;
return () {
_activeRunner = oldRunner;
assert(() {
final mountedCache = internalSidekickContextCache;
if (!identical(mountedCache, newCache)) {
throw "Tried to unmount the SidekickContext.cache but the currently "
"registered cache $mountedCache@${mountedCache.hashCode} is not the same "
"as the one that was mounted $newCache@${newCache.hashCode}.";
}
return true;
}());
internalSidekickContextCache = oldCache;
_entryWorkingDirectory = oldWorkingDirectory;
};
}