Skip to content

Commit f9ccd4a

Browse files
committed
feat(@probitas/probitas): add cache command to pre-download dependencies
Users often need to pre-download scenario dependencies before running tests, especially in CI/CD environments or when working offline. The new `probitas cache` command wraps `deno cache` with the same file discovery and configuration patterns as other CLI commands. Changes: - Added `probitas cache` command that runs `deno cache` on scenarios - Extended _deno.ts helper to support -r/--reload option - Created usage-cache.txt help documentation - Updated README and main help with cache command Usage: probitas cache # Cache all scenario dependencies probitas cache -r # Force re-download probitas cache api/ # Cache specific directory probitas cache --include "e2e/**/*.probitas.ts" The command follows the same patterns as fmt/lint/check for consistency and automatically discovers scenario files using probitas.json config.
1 parent 4386a17 commit f9ccd4a

7 files changed

Lines changed: 75 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ probitas list [options]
487487
# Initialize configuration file
488488
probitas init
489489

490+
# Cache scenario dependencies
491+
probitas cache [options]
492+
490493
# Format scenario files
491494
probitas fmt
492495

assets/usage-cache.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
probitas cache - Cache scenario dependencies
2+
3+
Usage: probitas cache [options] [paths...]
4+
5+
Arguments:
6+
[paths...] Scenario files or directories
7+
Defaults to current directory
8+
9+
Options:
10+
-h, --help Show help message
11+
-r, --reload Force re-download of cached dependencies
12+
--include <pattern> Include pattern for file discovery
13+
--exclude <pattern> Exclude pattern for file discovery
14+
--config <path> Path to probitas config file
15+
-v, --verbose Verbose output
16+
-q, --quiet Suppress output
17+
-d, --debug Debug output
18+
19+
Note:
20+
Runs `deno cache` on discovered scenario files to pre-download dependencies.
21+
Uses includes/excludes from probitas config (same as run/list).
22+
23+
Examples:
24+
probitas cache # Cache dependencies for all scenarios
25+
probitas cache api/ # Cache dependencies in api directory
26+
probitas cache -r # Force re-download all dependencies
27+
probitas cache -r api/ # Force re-download for api directory
28+
probitas cache --include "e2e/**/*.probitas.ts"
29+
30+
Documentation: https://probitas-test.github.io/documents/

assets/usage.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Commands:
66
init Initialize a new probitas project
77
run Run scenarios
88
list List available scenarios
9+
cache Cache scenario dependencies (runs deno cache)
910
fmt Format scenario files (runs deno fmt)
1011
lint Lint scenario files (runs deno lint)
1112
check Type-check scenario files (runs deno check)

src/cli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { parseArgs } from "@std/cli";
88
import { getLogger } from "@logtape/logtape";
99
import { EXIT_CODE } from "./cli/constants.ts";
10+
import { cacheCommand } from "./cli/commands/cache.ts";
1011
import { checkCommand } from "./cli/commands/check.ts";
1112
import { fmtCommand } from "./cli/commands/fmt.ts";
1213
import { initCommand } from "./cli/commands/init.ts";
@@ -81,6 +82,9 @@ export async function main(args: string[]): Promise<number> {
8182
case "list":
8283
return await listCommand(commandArgs, cwd);
8384

85+
case "cache":
86+
return await cacheCommand(commandArgs, cwd);
87+
8488
case "fmt":
8589
return await fmtCommand(commandArgs, cwd);
8690

src/cli/commands/_deno.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface DenoSubcommandOptions {
2626
usageAsset: string;
2727
/** Extra arguments to pass to the deno command */
2828
extraArgs?: readonly string[];
29+
/** Enable -r/--reload option support */
30+
supportReload?: boolean;
31+
/** Use deno.json/deno.lock config (default: false, adds --no-config) */
32+
useConfig?: boolean;
2933
}
3034

3135
/**
@@ -46,13 +50,14 @@ export async function runDenoSubcommand(
4650
try {
4751
const parsed = parseArgs(args, {
4852
string: ["config", "include", "exclude"],
49-
boolean: ["help", "quiet", "verbose", "debug"],
53+
boolean: ["help", "quiet", "verbose", "debug", "reload"],
5054
collect: ["include", "exclude"],
5155
alias: {
5256
h: "help",
5357
v: "verbose",
5458
q: "quiet",
5559
d: "debug",
60+
r: "reload",
5661
},
5762
default: {
5863
include: undefined,
@@ -108,10 +113,11 @@ export async function runDenoSubcommand(
108113
fileCount: scenarioFiles.length,
109114
});
110115

111-
// Run deno command with --no-config
116+
// Run deno command (with --no-config unless useConfig is true)
112117
const denoArgs = [
113118
subcommand,
114-
"--no-config",
119+
...(options.useConfig ? [] : ["--no-config"]),
120+
...(options.supportReload && parsed.reload ? ["--reload"] : []),
115121
...(options.extraArgs ?? []),
116122
...scenarioFiles,
117123
];

src/cli/commands/cache.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Cache command for Probitas CLI
3+
*
4+
* Runs `deno cache` on discovered scenario files to pre-download dependencies.
5+
*
6+
* @module
7+
*/
8+
9+
import { runDenoSubcommand } from "./_deno.ts";
10+
11+
/**
12+
* Run the cache command
13+
*
14+
* @param args - Command-line arguments
15+
* @param cwd - Current working directory
16+
* @returns Exit code
17+
*/
18+
export async function cacheCommand(
19+
args: string[],
20+
cwd: string,
21+
): Promise<number> {
22+
return await runDenoSubcommand("cache", args, cwd, {
23+
usageAsset: "usage-cache.txt",
24+
supportReload: true,
25+
useConfig: true,
26+
});
27+
}

src/cli/commands/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @module
55
*/
66

7+
export { cacheCommand } from "./cache.ts";
78
export { checkCommand } from "./check.ts";
89
export { fmtCommand } from "./fmt.ts";
910
export { initCommand } from "./init.ts";

0 commit comments

Comments
 (0)