mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
Maintainability, avoid bugs when not exiting after special commands
This commit is contained in:
1 parent
a896b032aa
commit
ba05b14e6f
1 file changed
+26
-26
@@ -5,19 +5,7 @@ var path = require('path')
|
||||
|
||||
// require config.json
|
||||
var config = require('./config');
|
||||
|
||||
var instance = process.argv[2];
|
||||
if (!instance || instance == "help" || instance == "--help") {
|
||||
console.error("Usage: ")
|
||||
console.error("node client.js [instance name]")
|
||||
console.error("node client.js list")
|
||||
console.error("node client.js delete [instance]")
|
||||
process.exit(1)
|
||||
}
|
||||
if (process.argv[2] == "list") {
|
||||
console.dir(getDirectories("./instances/"));
|
||||
process.exit(1)
|
||||
}
|
||||
// Functions
|
||||
var deleteFolderRecursive = function (path) {
|
||||
if (fs.existsSync(path)) {
|
||||
fs.readdirSync(path).forEach(function (file, index) {
|
||||
@@ -31,7 +19,28 @@ var deleteFolderRecursive = function (path) {
|
||||
fs.rmdirSync(path);
|
||||
}
|
||||
};
|
||||
if (process.argv[2] == "delete") {
|
||||
function getDirectories(srcpath) {
|
||||
return fs.readdirSync(srcpath).filter(function (file) {
|
||||
return fs.statSync(path.join(srcpath, file)).isDirectory();
|
||||
});
|
||||
}
|
||||
if (!fs.existsSync("./instances/")) {
|
||||
fs.mkdirSync("instances");
|
||||
}
|
||||
var instance = process.argv[2];
|
||||
var instancedirectory = './instances/' + instance;
|
||||
|
||||
// handle commandline parameters
|
||||
if (!instance || instance == "help" || instance == "--help") {
|
||||
console.error("Usage: ")
|
||||
console.error("node client.js [instance name]")
|
||||
console.error("node client.js list")
|
||||
console.error("node client.js delete [instance]")
|
||||
process.exit(1)
|
||||
} else if (process.argv[2] == "list") {
|
||||
console.dir(getDirectories("./instances/"));
|
||||
process.exit(1)
|
||||
} else if (process.argv[2] == "delete") {
|
||||
if (!process.argv[3]) {
|
||||
console.error("Usage: node client.js delete [instance]");
|
||||
process.exit(1)
|
||||
@@ -43,18 +52,8 @@ if (process.argv[2] == "delete") {
|
||||
console.error("Instance not found: " + process.argv[3]);
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
function getDirectories(srcpath) {
|
||||
return fs.readdirSync(srcpath).filter(function (file) {
|
||||
return fs.statSync(path.join(srcpath, file)).isDirectory();
|
||||
});
|
||||
}
|
||||
if (!fs.existsSync("./instances/")) {
|
||||
fs.mkdirSync("instances");
|
||||
}
|
||||
var instancedirectory = './instances/' + instance;
|
||||
// if instance does not exist, create it
|
||||
if (!fs.existsSync(instancedirectory)) {
|
||||
} else if (!fs.existsSync(instancedirectory)) {
|
||||
// if instance does not exist, create it
|
||||
console.log("Creating instance...")
|
||||
fs.mkdirSync(instancedirectory);
|
||||
fs.mkdirSync(instancedirectory + "/script-output/");
|
||||
@@ -101,6 +100,7 @@ write-data=__PATH__executable__\\..\\..\\..\\instances\\" + instance + "\r\n\
|
||||
'--create', instancedirectory + '/save.zip',
|
||||
]
|
||||
)
|
||||
console.log("Instance created!")
|
||||
}
|
||||
|
||||
var instanceconfig = require(instancedirectory + '/config');
|
||||
|
||||
Reference in new issue
Block a user