Skip to content

Commit 63b9cde

Browse files
authored
feat: add global pattern matching for compile command (#112)
* enhance: add glob pattern matching for compile command * style: format cli.ts * style: additional formatting fixes * refactor(cli): simplify circuit pattern matching to use regex directly
1 parent b1a8ba6 commit 63b9cde

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/cli.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@ function cli(args: string[]) {
1414
///////////////////////////////////////////////////////////////////////////////
1515
const circuit = new Command('compile')
1616
.description('compile the circuit')
17-
.argument('<circuit>', 'Circuit name')
18-
// .hook('preAction', () => titleLog('Compiling the circuit'))
19-
.action(async circuit => {
20-
const path = await circomkit.compile(circuit);
21-
circomkit.log.info('Built at:', path);
17+
.argument('[pattern]', 'Circuit name or pattern (defaults to ".*" for all circuits)')
18+
.action(async pattern => {
19+
const circuits = circomkit.readCircuits();
20+
const circuitNames = Object.keys(circuits);
21+
22+
if (!pattern) pattern = '.*';
23+
24+
const regex = new RegExp(`^${pattern}$`);
25+
const matchingCircuits = circuitNames.filter(name => regex.test(name));
2226

23-
// TODO: pattern matching https://github.com/erhant/circomkit/issues/79
27+
if (matchingCircuits.length === 0) {
28+
circomkit.log.info('No circuits found matching pattern:', pattern);
29+
return;
30+
}
31+
32+
for (const circuitName of matchingCircuits) {
33+
circomkit.log.info(`Compiling ${circuitName}...`);
34+
const path = await circomkit.compile(circuitName);
35+
circomkit.log.info(`Built at: ${path}`);
36+
}
2437
});
2538

2639
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)