1 | #!/usr/bin/env node
|
2 |
|
3 | var path = require("path"),
|
4 | nomnom = require("nomnom"),
|
5 | replace = require("../replace");
|
6 |
|
7 | var options = nomnom.opts({
|
8 | regex: {
|
9 | position: 0,
|
10 | help: "JavaScript regex for searching file e.g. '\\d+'",
|
11 | required: true
|
12 | },
|
13 | replacement: {
|
14 | position: 1,
|
15 | help: "Replacement string for matches",
|
16 | required: true
|
17 | },
|
18 | path: {
|
19 | position: 2,
|
20 | help: "File or directory to search (default is '.')",
|
21 | list: true,
|
22 | default: ["."]
|
23 | },
|
24 | recursive: {
|
25 | string: '-r, --recursive',
|
26 | help: "Recursively search and replace in directories"
|
27 | },
|
28 | preview: {
|
29 | string: '-p, --preview',
|
30 | help: "Preview the replacements, but don't modify files"
|
31 | },
|
32 | ignoreCase: {
|
33 | string: '-i, --ignore-case',
|
34 | help: "Ignore case when matching"
|
35 | },
|
36 | include: {
|
37 | string: '--include=PATHS',
|
38 | help: "Only search in these files, e.g. '*.js,*.foo'"
|
39 | },
|
40 | exclude: {
|
41 | string: '--exclude=PATHS',
|
42 | help: "Don't search in these files, e.g. '*.min.js'"
|
43 | },
|
44 | excludeList: {
|
45 | string: '--exclude-list=FILE',
|
46 | help: "File containing a new-line separated list of files to ignore",
|
47 | default: path.join(__dirname, "..", "defaultignore"),
|
48 | hidden: true
|
49 | },
|
50 | maxLines: {
|
51 | string: '-n NUMLINES',
|
52 | help: 'limit the number of lines to preview'
|
53 | },
|
54 | count: {
|
55 | string: '-c, --count',
|
56 | help: 'display count of occurances in each file'
|
57 | },
|
58 | quiet: {
|
59 | string: '-q, --quiet',
|
60 | help: "Just print the names of the files matches occured in (faster)"
|
61 | },
|
62 | silent: {
|
63 | string: '-s, --silent',
|
64 | help: "Don't print out anything"
|
65 | },
|
66 | color: {
|
67 | string: '--color=COLOR',
|
68 | help: "highlight color, e.g. 'green', 'blue', 'bold'",
|
69 | default: 'cyan'
|
70 | },
|
71 | async: {
|
72 | string: '-a, --async',
|
73 | help: "asynchronously read/write files in directory (faster)"
|
74 | }
|
75 | })
|
76 | .scriptName("replace")
|
77 | .parseArgs();
|
78 |
|
79 | replace(options);
|