alacritty-theme-switch
Version:
CLI utility for switching Alacritty color themes
29 lines (28 loc) • 987 B
JavaScript
import { errAsync, ResultAsync } from "neverthrow";
import { NoThemesFoundError } from "../theme-manager/errors.js";
import { safeDeleteFile, safeWalkAll, } from "../utils/fs-utils.js";
/**
* Execute the clear-themes command.
*
* Deletes all .toml theme files from the themes directory.
* Returns the original paths of all deleted files.
*
* @param options - Command options
* @returns A ResultAsync containing the count of deleted files or an error
*/
export function clearThemesCommand(options) {
return safeWalkAll(options.themesPath, {
exts: ["toml"],
includeFiles: true,
includeDirs: false,
})
.andThen((entries) => {
if (entries.length === 0) {
return errAsync(new NoThemesFoundError(options.themesPath));
}
const deleteResults = entries.map((entry) => {
return safeDeleteFile(entry.path).map(() => entry.path);
});
return ResultAsync.combine(deleteResults);
});
}