Skip to content

Commit c1eb38c

Browse files
committed
refactor: Add skip confirmation option
1 parent 36fd376 commit c1eb38c

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

packages/cli/lib/cli/commands/cache.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ cacheCommand.builder = function(cli) {
2020
.demandCommand(1, "Command required. Available command is 'clean'")
2121
.command("clean", "Remove all cached UI5 data", {
2222
handler: handleCache,
23-
builder: noop,
23+
builder: function(yargs) {
24+
return yargs.option("interactive", {
25+
describe: "Show confirmation prompt before cleaning. Use --no-interactive to skip (e.g. for CI)",
26+
default: true,
27+
type: "boolean",
28+
});
29+
},
2430
middlewares: [baseMiddleware],
2531
})
2632
.example("$0 cache clean",
27-
"Remove all cached UI5 data");
33+
"Remove all cached UI5 data")
34+
.example("$0 cache clean --no-interactive",
35+
"Remove all cached UI5 data without confirmation (CI mode)");
2836
};
2937

30-
function noop() {}
31-
3238
/**
3339
* Format a byte size as a human-readable string.
3440
*
@@ -66,7 +72,9 @@ async function confirm(question) {
6672
});
6773
}
6874

69-
async function handleCache() {
75+
async function handleCache(argv) {
76+
const interactive = argv?.interactive !== false;
77+
7078
// Resolve UI5 data directory
7179
let ui5DataDir = process.env.UI5_DATA_DIR;
7280
if (!ui5DataDir) {
@@ -105,11 +113,13 @@ async function handleCache() {
105113
}
106114
process.stderr.write(chalk.bold(`\nTotal: ${formatSize(totalSize)}\n\n`));
107115

108-
// Ask for confirmation
109-
const confirmed = await confirm("Do you want to continue? (y/N) ");
110-
if (!confirmed) {
111-
process.stderr.write("Cancelled\n");
112-
return;
116+
// Ask for confirmation (skip in non-interactive mode)
117+
if (interactive) {
118+
const confirmed = await confirm("Do you want to continue? (y/N) ");
119+
if (!confirmed) {
120+
process.stderr.write("Cancelled\n");
121+
return;
122+
}
113123
}
114124

115125
// Perform the actual cleanup (orchestrate both domains)

packages/cli/test/lib/cli/commands/cache.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test("Command builder", async (t) => {
7171
t.is(result, cliStub, "Builder returns cli instance");
7272
t.is(cliStub.demandCommand.callCount, 1, "demandCommand called once");
7373
t.is(cliStub.command.callCount, 1, "command called once");
74-
t.is(cliStub.example.callCount, 1, "example called once");
74+
t.is(cliStub.example.callCount, 2, "example called twice");
7575
});
7676

7777
test.serial("ui5 cache clean: nothing to clean", async (t) => {
@@ -253,3 +253,32 @@ test.serial("ui5 cache clean: uses config.getUi5DataDir when no env var", async
253253
}
254254
}
255255
});
256+
257+
test.serial("ui5 cache clean --no-interactive: skips confirmation prompt", async (t) => {
258+
const {cache, argv, stderrWriteStub, frameworkCacheCleanCache, frameworkCacheGetCacheInfo,
259+
buildCacheCleanCache, buildCacheGetCacheInfo, mockRLInterface} = t.context;
260+
261+
frameworkCacheGetCacheInfo.resolves({path: "framework/", size: 10 * 1024 * 1024, type: "directory"});
262+
buildCacheGetCacheInfo.resolves({
263+
path: "buildCache/v0_7 (database records)", size: 5 * 1024 * 1024, type: "database"
264+
});
265+
266+
frameworkCacheCleanCache.resolves({path: "framework", type: "framework", size: 10 * 1024 * 1024});
267+
buildCacheCleanCache.resolves({path: "buildCache/v0_7", type: "buildCache", size: 5 * 1024 * 1024});
268+
269+
argv["_"] = ["cache", "clean"];
270+
argv["interactive"] = false;
271+
await cache.handler(argv);
272+
273+
// Confirmation should NOT be asked
274+
t.is(mockRLInterface.question.callCount, 0, "Should not ask for confirmation in non-interactive mode");
275+
276+
// Cleanup should still proceed
277+
t.is(frameworkCacheCleanCache.callCount, 1, "frameworkCache.cleanCache should be called");
278+
t.is(buildCacheCleanCache.callCount, 1, "buildCache.cleanCache should be called");
279+
280+
// Check output
281+
const allOutput = stderrWriteStub.args.map((a) => a[0]).join("");
282+
t.true(allOutput.includes("following items from cache will be removed"), "Shows items to be removed");
283+
t.true(allOutput.includes("Success"), "Shows success message");
284+
});

0 commit comments

Comments
 (0)