forked from holesail/holesail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (71 loc) · 2.39 KB
/
index.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
#!/usr/bin/env node
const argv = require('minimist')(process.argv.slice(2)); // Required to parse CLI arguments
const goodbye = require('graceful-goodbye');
const pkg = require('./package.json'); // Holds info about the current package
var colors = require('colors/safe');
// Require all necessary files
const help = require('./includes/help.js');
const Client = require('./includes/client.js');
const Server = require('./includes/server.js');
const Filemanager = require('./includes/livefiles.js'); // Adjust the path as needed
const { ValidateInput } = require('./includes/validateInput.js');
// Validate every input and throw errors if incorrect input
const validator = new ValidateInput(argv);
// Setting up the command hierarchy
// Display help and exit
if (argv.help) {
help.printHelp(help.helpMessage);
process.exit(-1);
}
// Display version and exit
if (argv.version) {
console.log(pkg.version);
process.exit(-1);
}
// Set a port live
if (argv.live) {
const options = {
port: argv.live,
host: argv.host,
connector: argv.connector,
public: argv.public,
service: "Server"
};
const server = new Server(options);
server.start();
goodbye(async () => {
await server.destroy();
});
} else if (argv.connect || argv['_'][0]) { // Establish connection with a peer
const keyInput = argv.connect || argv['_'][0];
const options = {
port: argv.port || 8989,
host: argv.host || '127.0.0.1',
connector: argv.connector
};
const client = new Client(keyInput, options);
client.start();
} else if ( argv.filemanager ) { // Start server with a filemanager
const options = {
//options for the file manager
path: argv.filemanager,
username: argv.username,
password: argv.password,
role: argv.role,
//options for holesail-server
port: argv.port,
connector: argv.connector,
public: argv.public,
service: "Filemanager"
};
// Start files server
const fileServer = new Filemanager(options);
fileServer.start();
//destroy before exiting
goodbye(async () => {
await fileServer.destroy();
});
} else { // Default if no correct option is chosen
console.log(colors.red(`Error: Invalid or Incorrect arguments specified. See holesail --help for a list of all valid arguments`));
process.exit(2);
}