Merge pull request #1350 from thelounge/xpaw/proper-cli

Only create config folder in 'start' command
This commit is contained in:
Jérémie Astori 2017-08-26 12:17:10 -04:00 committed by GitHub
commit f7ecd0a053
9 changed files with 102 additions and 56 deletions

View file

@ -41,7 +41,7 @@ ClientManager.prototype.autoloadUsers = function() {
process.exit(1);
}
if (!users.length) {
if (users.length === 0) {
log.info(noUsersWarning);
}
@ -51,7 +51,7 @@ ClientManager.prototype.autoloadUsers = function() {
const loaded = this.clients.map((c) => c.name);
const updatedUsers = this.getUsers();
if (!updatedUsers.length) {
if (updatedUsers.length === 0) {
log.info(noUsersWarning);
}

View file

@ -1,9 +1,9 @@
"use strict";
var ClientManager = new require("../clientManager");
var colors = require("colors/safe");
var program = require("commander");
var Helper = require("../helper");
const colors = require("colors/safe");
const program = require("commander");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
program
@ -11,6 +11,13 @@ program
.description("Add a new user")
.on("--help", Utils.extraHelp)
.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) {
log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
}

View file

@ -1,9 +1,10 @@
"use strict";
var program = require("commander");
var child = require("child_process");
var colors = require("colors/safe");
var Helper = require("../helper");
const program = require("commander");
const child = require("child_process");
const colors = require("colors/safe");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
program
@ -11,6 +12,11 @@ program
.description(`Edit configuration file located at ${colors.green(Helper.CONFIG_PATH)}.`)
.on("--help", Utils.extraHelp)
.action(function() {
if (!fs.existsSync(Helper.CONFIG_PATH)) {
log.error(`${Helper.CONFIG_PATH} does not exist.`);
return;
}
var child_spawn = child.spawn(
process.env.EDITOR || "vi",
[Helper.CONFIG_PATH],

View file

@ -1,10 +1,10 @@
"use strict";
var ClientManager = new require("../clientManager");
var program = require("commander");
var child = require("child_process");
var colors = require("colors/safe");
var Helper = require("../helper");
const program = require("commander");
const child = require("child_process");
const colors = require("colors/safe");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
program
@ -12,6 +12,13 @@ program
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`)
.on("--help", Utils.extraHelp)
.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();
if (users === undefined) { // There was an error, already logged

View file

@ -2,12 +2,9 @@
global.log = require("../log.js");
var program = require("commander");
var colors = require("colors/safe");
var fs = require("fs");
var fsextra = require("fs-extra");
var path = require("path");
var Helper = require("../helper");
const program = require("commander");
const colors = require("colors/safe");
const Helper = require("../helper");
const Utils = require("./utils");
program.version(Helper.getVersion(), "-v, --version")
@ -28,21 +25,6 @@ if (!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("./config");
require("./list");

View file

@ -1,8 +1,8 @@
"use strict";
var ClientManager = new require("../clientManager");
var program = require("commander");
var colors = require("colors/safe");
const colors = require("colors/safe");
const program = require("commander");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
@ -11,6 +11,13 @@ program
.description("List all users")
.on("--help", Utils.extraHelp)
.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) {
log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
}
@ -21,12 +28,12 @@ program
return;
}
if (!users.length) {
log.info(`There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`);
} else {
if (users.length > 0) {
log.info("Users:");
for (var i = 0; i < users.length; i++) {
log.info(`${i + 1}. ${colors.bold(users[i])}`);
}
users.forEach((user, i) => {
log.info(`${i + 1}. ${colors.bold(user)}`);
});
} else {
log.info(`There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`);
}
});

View file

@ -1,8 +1,9 @@
"use strict";
var ClientManager = new require("../clientManager");
var program = require("commander");
var colors = require("colors/safe");
const colors = require("colors/safe");
const program = require("commander");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
program
@ -10,6 +11,12 @@ program
.description("Remove an existing user")
.on("--help", Utils.extraHelp)
.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();
try {

View file

@ -1,10 +1,9 @@
"use strict";
var ClientManager = new require("../clientManager");
var fs = require("fs");
var program = require("commander");
var colors = require("colors/safe");
var Helper = require("../helper");
const colors = require("colors/safe");
const program = require("commander");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
program
@ -12,6 +11,13 @@ program
.description("Reset user password")
.on("--help", Utils.extraHelp)
.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();
if (users === undefined) { // There was an error, already logged

View file

@ -1,8 +1,11 @@
"use strict";
var program = require("commander");
var server = require("../server");
var Helper = require("../helper");
const colors = require("colors/safe");
const fs = require("fs");
const fsextra = require("fs-extra");
const path = require("path");
const program = require("commander");
const Helper = require("../helper");
const Utils = require("./utils");
program
@ -15,6 +18,10 @@ program
.description("Start the server")
.on("--help", Utils.extraHelp)
.action(function(options) {
initalizeConfig();
const server = require("../server");
var mode = Helper.config.public;
if (options.public) {
mode = true;
@ -29,3 +36,20 @@ program
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);
}