-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
49 lines (41 loc) · 1.82 KB
/
Copy pathcli.js
File metadata and controls
49 lines (41 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
import { Command } from 'commander';
import path from 'path';
import { loadConfig } from './config.js';
import { runAttach } from './attach.js';
import { logger } from './logger.js';
const program = new Command();
program
.name('sqlattach')
.description('CLI to automate attaching SQL Server databases in Docker')
.version('1.0.0')
.argument('<path>', 'Directory containing MDF/LDF files to scan and attach')
.option('-n, --name <name>', 'Specific name for the database (only works if 1 DB is found)')
.option('--replace', 'Overwrite existing database with the same name', false)
.option('-p, --parallel <number>', 'Number of concurrent attach operations', parseInt)
.option('--container <name>', 'Docker container name')
.option('--dry-run', 'Show what would be done without making changes', false)
.action(async (targetPath, options) => {
try {
const fullPath = path.resolve(targetPath);
logger.info(`Starting sqlattach on path: ${fullPath}`);
const config = loadConfig({
replace: options.replace,
parallel: options.parallel,
container: options.container,
});
const result = await runAttach(fullPath, config, options);
console.log('\n════════════════════════════════════');
console.log(` Tempo........ ${Math.round(result.timeMs / 1000)} s`);
console.log(` Sucesso...... ${result.success}`);
console.log(` Falha........ ${result.failed}`);
console.log('════════════════════════════════════\n');
if (result.failed > 0) {
process.exit(1);
}
} catch (err) {
logger.error(`Critical error: ${err.message}`);
process.exit(1);
}
});
program.parse();