-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCliValidator.ts
More file actions
33 lines (25 loc) · 866 Bytes
/
CliValidator.ts
File metadata and controls
33 lines (25 loc) · 866 Bytes
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
import * as fs from 'fs';
export default class CliValidator {
public static isFilePath(path: string): boolean {
if (!path) {
console.log('Error: Please supply the path to the configuration file.\n');
return false;
}
let file: number;
try {
file = fs.openSync(path, 'r')
} catch (error) {
console.log(`Error: Given path '${path}' does not exist. Error: ${error}`);
return false;
}
return CliValidator.isFile(file, path);
}
private static isFile(file: number, path: string): boolean {
const fileStats = fs.fstatSync(file);
if (!fileStats.isFile()) {
console.log(`Error: Given path '${path}' is not a file`);
return false;
}
return true;
}
}