UNPKG

@sap/cli-core

Version:

Command-Line Interface (CLI) Core Module

27 lines (26 loc) 1.08 kB
import { cleanCache, deleteFile, getFiles } from "../../../cache/index.js"; import { DISCOVERY_DOCUMENT_PREFIX } from "../../../constants.js"; import { getOptionValueFromConfigGracefully } from "../../../utils/options.js"; import { createNextHandler, createParseArgumentsHandler, } from "../../handler/index.js"; const OPTION_PURGE_ALL = { longName: "purge-all", description: "clean the whole local CLI cache", }; const cleanHandler = async () => async () => { const purgeAll = getOptionValueFromConfigGracefully(OPTION_PURGE_ALL); if (purgeAll) { await cleanCache(); } else { const files = (await getFiles()).filter((file) => file.startsWith(DISCOVERY_DOCUMENT_PREFIX)); await Promise.all(files.map(async (file) => deleteFile(file))); } }; const cleanCommand = { type: "command", command: "clean", description: "clean the local CLI cache", handler: createNextHandler("command.config.cache.clean", createParseArgumentsHandler(), cleanHandler), options: [OPTION_PURGE_ALL], }; export default cleanCommand;