Skip to content

Commit

Permalink
cli: add --ignore and --only options
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Jul 27, 2024
1 parent 154eeca commit b34e85d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const main = new Command()
)
.option("--config <file:string>", "Specify the Deno configuration file.")
.option("--dry-run", "See what would happen without actually doing it.")
.option("--filter <pattern:string>", "Filter dependencies by name.")
.option("--ignore <pattern:string>", "Specify dependencies to ignore.")
.option("--only <pattern:string>", "Specify dependencies to check.")
.option("--lock <file:string>", "Specify the lock file.")
.option("--no-config", "Disable automatic loading of the configuration file.")
.option("--no-lock", "Disable automatic loading of the lock file.")
Expand Down Expand Up @@ -63,7 +64,9 @@ main.action(async function (options, ...source) {
const deps = await $.progress("Collecting dependencies").with(
() => collect({ config, lock, source }),
);
const filtered = deps.filter((dep) => dep.name.match(options.filter ?? ""));
const filtered = deps
.filter((dep) => options.only ? dep.name.match(options.only) : true)
.filter((dep) => options.ignore ? !dep.name.match(options.ignore) : true);

const updates = (await $.progress("Fetching updates").with(() =>
Promise.all(filtered.map((dep) =>
Expand Down
15 changes: 13 additions & 2 deletions cli/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ describe("CLI", () => {
);
});

it("should filter dependencies with `--filter`", async () => {
const { stdout } = await molt("--filter flag");
it("should filter dependencies with `--only`", async () => {
const { stdout } = await molt("--only flag");
assertEquals(
stdout,
dedent`
Expand All @@ -124,6 +124,17 @@ describe("CLI", () => {
);
});

it("should filter out dependencies with `--ignore`", async () => {
const { stdout } = await molt("--ignore flag");
assertEquals(
stdout,
dedent`
📦 @conventional-commits/parser 0.4.0 → 0.4.1
📦 deno.land/std 0.222.0 → 0.224.0
`,
);
});

it("should find updates in modules with `--no-config`", async () => {
const { stdout } = await molt("--no-config");
assertEquals(
Expand Down

0 comments on commit b34e85d

Please sign in to comment.