mirror of
https://github.com/thelounge/thelounge
synced 2024-11-29 23:40:28 +00:00
Merge pull request #1350 from thelounge/xpaw/proper-cli
Only create config folder in 'start' command
This commit is contained in:
commit
f7ecd0a053
9 changed files with 102 additions and 56 deletions
|
@ -41,7 +41,7 @@ ClientManager.prototype.autoloadUsers = function() {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!users.length) {
|
if (users.length === 0) {
|
||||||
log.info(noUsersWarning);
|
log.info(noUsersWarning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ ClientManager.prototype.autoloadUsers = function() {
|
||||||
const loaded = this.clients.map((c) => c.name);
|
const loaded = this.clients.map((c) => c.name);
|
||||||
const updatedUsers = this.getUsers();
|
const updatedUsers = this.getUsers();
|
||||||
|
|
||||||
if (!updatedUsers.length) {
|
if (updatedUsers.length === 0) {
|
||||||
log.info(noUsersWarning);
|
log.info(noUsersWarning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ClientManager = new require("../clientManager");
|
const colors = require("colors/safe");
|
||||||
var colors = require("colors/safe");
|
const program = require("commander");
|
||||||
var program = require("commander");
|
const fs = require("fs");
|
||||||
var Helper = require("../helper");
|
const Helper = require("../helper");
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -11,6 +11,13 @@ program
|
||||||
.description("Add a new user")
|
.description("Add a new user")
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function(name) {
|
.action(function(name) {
|
||||||
|
if (!fs.existsSync(Helper.USERS_PATH)) {
|
||||||
|
log.error(`${Helper.USERS_PATH} does not exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ClientManager = require("../clientManager");
|
||||||
|
|
||||||
if (Helper.config.public) {
|
if (Helper.config.public) {
|
||||||
log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
|
log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var program = require("commander");
|
const program = require("commander");
|
||||||
var child = require("child_process");
|
const child = require("child_process");
|
||||||
var colors = require("colors/safe");
|
const colors = require("colors/safe");
|
||||||
var Helper = require("../helper");
|
const fs = require("fs");
|
||||||
|
const Helper = require("../helper");
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -11,6 +12,11 @@ program
|
||||||
.description(`Edit configuration file located at ${colors.green(Helper.CONFIG_PATH)}.`)
|
.description(`Edit configuration file located at ${colors.green(Helper.CONFIG_PATH)}.`)
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function() {
|
.action(function() {
|
||||||
|
if (!fs.existsSync(Helper.CONFIG_PATH)) {
|
||||||
|
log.error(`${Helper.CONFIG_PATH} does not exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var child_spawn = child.spawn(
|
var child_spawn = child.spawn(
|
||||||
process.env.EDITOR || "vi",
|
process.env.EDITOR || "vi",
|
||||||
[Helper.CONFIG_PATH],
|
[Helper.CONFIG_PATH],
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ClientManager = new require("../clientManager");
|
const program = require("commander");
|
||||||
var program = require("commander");
|
const child = require("child_process");
|
||||||
var child = require("child_process");
|
const colors = require("colors/safe");
|
||||||
var colors = require("colors/safe");
|
const fs = require("fs");
|
||||||
var Helper = require("../helper");
|
const Helper = require("../helper");
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -12,6 +12,13 @@ program
|
||||||
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`)
|
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`)
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function(name) {
|
.action(function(name) {
|
||||||
|
if (!fs.existsSync(Helper.USERS_PATH)) {
|
||||||
|
log.error(`${Helper.USERS_PATH} does not exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ClientManager = require("../clientManager");
|
||||||
|
|
||||||
var users = new ClientManager().getUsers();
|
var users = new ClientManager().getUsers();
|
||||||
|
|
||||||
if (users === undefined) { // There was an error, already logged
|
if (users === undefined) { // There was an error, already logged
|
||||||
|
|
|
@ -2,12 +2,9 @@
|
||||||
|
|
||||||
global.log = require("../log.js");
|
global.log = require("../log.js");
|
||||||
|
|
||||||
var program = require("commander");
|
const program = require("commander");
|
||||||
var colors = require("colors/safe");
|
const colors = require("colors/safe");
|
||||||
var fs = require("fs");
|
const Helper = require("../helper");
|
||||||
var fsextra = require("fs-extra");
|
|
||||||
var path = require("path");
|
|
||||||
var Helper = require("../helper");
|
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
program.version(Helper.getVersion(), "-v, --version")
|
program.version(Helper.getVersion(), "-v, --version")
|
||||||
|
@ -28,21 +25,6 @@ if (!home) {
|
||||||
|
|
||||||
Helper.setHome(home);
|
Helper.setHome(home);
|
||||||
|
|
||||||
if (!fs.existsSync(Helper.CONFIG_PATH)) {
|
|
||||||
fsextra.ensureDirSync(Helper.HOME);
|
|
||||||
fs.chmodSync(Helper.HOME, "0700");
|
|
||||||
fsextra.copySync(path.resolve(path.join(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"..",
|
|
||||||
"defaults",
|
|
||||||
"config.js"
|
|
||||||
)), Helper.CONFIG_PATH);
|
|
||||||
log.info(`Configuration file created at ${colors.green(Helper.CONFIG_PATH)}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
fsextra.ensureDirSync(Helper.USERS_PATH);
|
|
||||||
|
|
||||||
require("./start");
|
require("./start");
|
||||||
require("./config");
|
require("./config");
|
||||||
require("./list");
|
require("./list");
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ClientManager = new require("../clientManager");
|
const colors = require("colors/safe");
|
||||||
var program = require("commander");
|
const program = require("commander");
|
||||||
var colors = require("colors/safe");
|
const fs = require("fs");
|
||||||
const Helper = require("../helper");
|
const Helper = require("../helper");
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
|
@ -11,6 +11,13 @@ program
|
||||||
.description("List all users")
|
.description("List all users")
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function() {
|
.action(function() {
|
||||||
|
if (!fs.existsSync(Helper.USERS_PATH)) {
|
||||||
|
log.error(`${Helper.USERS_PATH} does not exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ClientManager = require("../clientManager");
|
||||||
|
|
||||||
if (Helper.config.public) {
|
if (Helper.config.public) {
|
||||||
log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
|
log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
|
||||||
}
|
}
|
||||||
|
@ -21,12 +28,12 @@ program
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!users.length) {
|
if (users.length > 0) {
|
||||||
log.info(`There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`);
|
|
||||||
} else {
|
|
||||||
log.info("Users:");
|
log.info("Users:");
|
||||||
for (var i = 0; i < users.length; i++) {
|
users.forEach((user, i) => {
|
||||||
log.info(`${i + 1}. ${colors.bold(users[i])}`);
|
log.info(`${i + 1}. ${colors.bold(user)}`);
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
|
log.info(`There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ClientManager = new require("../clientManager");
|
const colors = require("colors/safe");
|
||||||
var program = require("commander");
|
const program = require("commander");
|
||||||
var colors = require("colors/safe");
|
const fs = require("fs");
|
||||||
|
const Helper = require("../helper");
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -10,6 +11,12 @@ program
|
||||||
.description("Remove an existing user")
|
.description("Remove an existing user")
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function(name) {
|
.action(function(name) {
|
||||||
|
if (!fs.existsSync(Helper.USERS_PATH)) {
|
||||||
|
log.error(`${Helper.USERS_PATH} does not exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ClientManager = require("../clientManager");
|
||||||
const manager = new ClientManager();
|
const manager = new ClientManager();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ClientManager = new require("../clientManager");
|
const colors = require("colors/safe");
|
||||||
var fs = require("fs");
|
const program = require("commander");
|
||||||
var program = require("commander");
|
const fs = require("fs");
|
||||||
var colors = require("colors/safe");
|
const Helper = require("../helper");
|
||||||
var Helper = require("../helper");
|
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -12,6 +11,13 @@ program
|
||||||
.description("Reset user password")
|
.description("Reset user password")
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function(name) {
|
.action(function(name) {
|
||||||
|
if (!fs.existsSync(Helper.USERS_PATH)) {
|
||||||
|
log.error(`${Helper.USERS_PATH} does not exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ClientManager = require("../clientManager");
|
||||||
|
|
||||||
var users = new ClientManager().getUsers();
|
var users = new ClientManager().getUsers();
|
||||||
|
|
||||||
if (users === undefined) { // There was an error, already logged
|
if (users === undefined) { // There was an error, already logged
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var program = require("commander");
|
const colors = require("colors/safe");
|
||||||
var server = require("../server");
|
const fs = require("fs");
|
||||||
var Helper = require("../helper");
|
const fsextra = require("fs-extra");
|
||||||
|
const path = require("path");
|
||||||
|
const program = require("commander");
|
||||||
|
const Helper = require("../helper");
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -15,6 +18,10 @@ program
|
||||||
.description("Start the server")
|
.description("Start the server")
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function(options) {
|
.action(function(options) {
|
||||||
|
initalizeConfig();
|
||||||
|
|
||||||
|
const server = require("../server");
|
||||||
|
|
||||||
var mode = Helper.config.public;
|
var mode = Helper.config.public;
|
||||||
if (options.public) {
|
if (options.public) {
|
||||||
mode = true;
|
mode = true;
|
||||||
|
@ -29,3 +36,20 @@ program
|
||||||
|
|
||||||
server();
|
server();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function initalizeConfig() {
|
||||||
|
if (!fs.existsSync(Helper.CONFIG_PATH)) {
|
||||||
|
fsextra.ensureDirSync(Helper.HOME);
|
||||||
|
fs.chmodSync(Helper.HOME, "0700");
|
||||||
|
fsextra.copySync(path.resolve(path.join(
|
||||||
|
__dirname,
|
||||||
|
"..",
|
||||||
|
"..",
|
||||||
|
"defaults",
|
||||||
|
"config.js"
|
||||||
|
)), Helper.CONFIG_PATH);
|
||||||
|
log.info(`Configuration file created at ${colors.green(Helper.CONFIG_PATH)}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
fsextra.ensureDirSync(Helper.USERS_PATH);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue