class DryRunTracker {
constructor() {
this.executedStrings = [];
this.overrides = {};
}
/**
* Executes a string and tracks its execution.
* @param {string} str The string to execute.
* @param {Function} callback Optional callback function to execute after the string.
* @returns {boolean} True if the string was executed, false otherwise.
*/
execute(str, callback = null) {
this.executedStrings.push(str);
// Check for overrides
if (this.overrides[str]) {
console.warn(`Dry-run: String "${str}" is overridden.`);
return false; //Don't actually execute the string
}
try {
// Simulate execution. Replace with actual execution logic if needed.
console.log(`Dry-run: Executing string: ${str}`);
if (callback) {
callback();
}
return true;
} catch (error) {
console.error(`Dry-run: Error executing string "${str}":`, error);
return false;
}
}
/**
* Sets an override for a string. Prevents the string from being executed.
* @param {string} str The string to override.
* @param {any} value The override value.
*/
override(str, value) {
this.overrides[str] = value;
}
/**
* Returns the list of executed strings.
* @returns {string[]} The list of executed strings.
*/
getExecutedStrings() {
return this.executedStrings;
}
/**
* Returns the current overrides.
* @returns {object} The overrides object.
*/
getOverrides() {
return this.overrides;
}
}
// Export the class (if needed for module use)
export default DryRunTracker;
Add your comment