-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
83 lines (66 loc) · 2.03 KB
/
cli.js
File metadata and controls
83 lines (66 loc) · 2.03 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
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
'use strict';
const mPath = require('path');
const mFs = require('fs');
const ModuleManager = require('./moduleManager.js');
const cmd = (process.argv[2] || '').replace(/\/+$/, '');
const basePath = (process.argv[3] || '').replace(/\/+$/, '');
class Cli {
init(path) {
if(path) {
this._resolved = mPath.resolve(path);
}
this._commands = {
reqursion: this._cmdFindRequrions,
path: this._cmdCheckPaths
};
return this;
}
run(cmd) {
if(this._commands.hasOwnProperty(cmd)) {
this._commands[cmd].call(this);
} else {
this._cmdHelp(cmd);
}
return this;
}
_checkPath() {
if(!this._resolved) {
console.log('Specify the path to your files');
return false;
}
if(!mFs.existsSync(this._resolved)) {
console.log(`Path does not exist: "${this._resolved}"`);
return false;
}
return true;
}
_cmdFindRequrions() {
if(this._checkPath()) {
let manager = new ModuleManager();
manager.findReqursions(this._resolved, function(result) {
if(result) {
for(var key in result) {
console.log('\n@ Reqursion in', result[key].path, result[key].stack.map(function(value, index) {
return '\n\t' + (index+1) + '. ' + value;
}).join(''));
}
} else {
console.log('Good boy');
}
});
}
}
_cmdCheckPaths() {
if(this._checkPath()) {
let manager = new ModuleManager();
manager.findInvalidPaths(this._resolved);
}
}
_cmdHelp(cmd) {
var cmdList = Object.keys(this._commands);
console.log('%s: command not found \'\'.\n\nUsage: cli [COMMAND] [PATH]\n\nCommands:\n\t%s', cmd, cmdList.join('\n\t'));
}
}
new Cli()
.init(basePath)
.run(cmd);