-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
99 lines (84 loc) · 2.3 KB
/
cli.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const makeDirRange = require('make-dir-range');
const moveToRange = require('move-to-range');
const copyToRange = require('copy-to-range');
const cli = meow(`
Usage
$ ranger make <range> <options>
Make directories from ranges of integers.
Options:
--destination, -d Destination for dirs
--prepend, -p Prepend to destination dir names
--append, -a Append to destination dir names
$ ranger move <range> <file-type> <options>
Move files to corresponding directories given a range.
Options:
--destination, -d Destination for dirs
--prepend, -p Prepend to destination dir names
--append, -a Append to destination dir names
$ ranger copy <file> <range> <options>
Copy a file to a range of directories.
Options:
--destination, -d Destination for dirs
Examples
$ ranger make 1-5,7-10
$ ranger move 101-153 .txt --destination output
$ ragner copy file.txt 11-15,18,20-25
`, {
flags: {
append: {
type: 'string',
default: '',
alias: 'a'
},
prepend: {
type: 'string',
default: '',
alias: 'p'
},
destination: {
type: 'string',
default: '',
alias: 'd'
}
}
});
const input = cli.input;
if (input.length === 0) {
console.error('No command provided');
process.exit(1);
}
if (input.length === 1) {
console.error('No args provided');
process.exit(1);
}
switch (input[0]) {
case "make":
case "mk":
case "mkdir":
makeDirRange(input[1], cli.flags);
break;
case "move":
case "mv":
if (input.length === 2) {
console.error('No file type provided');
process.exit(1);
}
moveToRange(input[1], input[2], cli.flags);
break;
case "copy":
case "cp":
if (input.length === 2) {
console.error('No range provided');
process.exit(1);
}
copyToRange(input[1], input[2], cli.flags);
break;
default:
console.error(`Invalid command ${input[1]}`);
process.exit(1);
break;
}
process.exit(1);