-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·91 lines (79 loc) · 2.04 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
#! /usr/bin/env node
'use strict';
const meow = require('meow');
const sortifiler = require('sortifiler');
const fs = require('fs');
const cli = meow(`
Usage
$ sortfiler <path>
Options
no flags, Sorts all files and folders in a given path.
--files, -f Sort all files in a given path.
--folders, -F Sort all folders in a given path.
--config, -c <filePath> Use a custom configuration file.
<path> is the path to directory that needs sorting
Examples
Sort all files and folders in the Downloads folder.
$ sortifiler ~/Downloads
Sorting ...
Sorted ✔
Sort all files on the Desktop
$ sortifiler ~/Desktop --files
Sorting files ...
Sorted ✔
Sort all folders in the Downloads folder
$ sortifiler ~/Downloads --folders
Sorting folders ...
Sorted ✔
Sort all files and folders on the Desktop using a custom configuration file
$ sortifiler ~/Desktop --config sortifiler.json
Loaded configuration ✔
Sorting folders ...
Sorted ✔
`, {
flags: {
help: {
type: 'boolean',
alias: 'h'
},
version: {
type: 'boolean',
alias: 'v'
},
files: {
type: 'boolean',
alias: 'f'
},
folders: {
type: 'boolean',
alias: 'F'
},
config: {
type: 'boolean',
alias: 'c'
},
}
});
const flags = cli.unnormalizedFlags;
if (flags.config || flags.c) {
if (cli.input.length > 2) {
console.log('Invalid file!');
return;
} else {
const configFile = fs.readFileSync(cli.input[1]);
const configData = JSON.parse(configFile);
sortifiler.config(configData);
}
console.log('Loaded configuration ✔')
}
if (flags.files || flags.f) {
console.log('Sorting files ...');
sortifiler.sortFiles(cli.input[0]);
} else if (flags.folders || flags.F) {
console.log('Sorting folders ...');
sortifiler.sortFolders(cli.input[0]);
} else {
console.log('Sorting ...');
sortifiler.sortAll(cli.input[0]);
}
console.log('Sorted ✔');