UNPKG

1.08 kBPlain TextView Raw
1#!/usr/bin/env node
2
3
4
5
6var ncp = require('../lib/ncp'),
7 args = process.argv.slice(2),
8 source, dest;
9
10if (args.length < 2) {
11 console.error('Usage: ncp [source] [destination] [--filter=filter] [--limit=concurrency limit]');
12 process.exit(1);
13}
14
15// parse arguments the hard way
16function startsWith(str, prefix) {
17 return str.substr(0, prefix.length) == prefix;
18}
19
20var options = {};
21args.forEach(function (arg) {
22 if (startsWith(arg, "--limit=")) {
23 options.limit = parseInt(arg.split('=', 2)[1], 10);
24 }
25 if (startsWith(arg, "--filter=")) {
26 options.filter = new RegExp(arg.split('=', 2)[1]);
27 }
28 if (startsWith(arg, "--stoponerr")) {
29 options.stopOnErr = true;
30 }
31});
32
33ncp.ncp(args[0], args[1], options, function (err) {
34 if (Array.isArray(err)) {
35 console.error('There were errors during the copy.');
36 err.forEach(function (err) {
37 console.error(err.stack || err.message);
38 });
39 process.exit(1);
40 }
41 else if (err) {
42 console.error('An error has occurred.');
43 console.error(err.stack || err.message);
44 process.exit(1);
45 }
46});
47
48