Merge pull request #1438 from thelounge/astorije/env-var-doc

Add documentation for LOUNGE_HOME environment variable in the CLI helper
This commit is contained in:
Jérémie Astori 2017-08-22 09:30:51 -04:00 committed by GitHub
commit b0b2518e10
9 changed files with 56 additions and 9 deletions

View File

@ -4,10 +4,12 @@ var ClientManager = new require("../clientManager");
var colors = require("colors/safe");
var program = require("commander");
var Helper = require("../helper");
const Utils = require("./utils");
program
.command("add <name>")
.description("Add a new user")
.on("--help", Utils.extraHelp)
.action(function(name) {
var manager = new ClientManager();
var users = manager.getUsers();

View File

@ -4,10 +4,12 @@ var program = require("commander");
var child = require("child_process");
var colors = require("colors/safe");
var Helper = require("../helper");
const Utils = require("./utils");
program
.command("config")
.description(`Edit configuration file located at ${colors.green(Helper.CONFIG_PATH)}. Set the ${colors.green("LOUNGE_HOME")} environment variable to change.`)
.description(`Edit configuration file located at ${colors.green(Helper.CONFIG_PATH)}.`)
.on("--help", Utils.extraHelp)
.action(function() {
var child_spawn = child.spawn(
process.env.EDITOR || "vi",

View File

@ -5,10 +5,12 @@ var program = require("commander");
var child = require("child_process");
var colors = require("colors/safe");
var Helper = require("../helper");
const Utils = require("./utils");
program
.command("edit <name>")
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`)
.on("--help", Utils.extraHelp)
.action(function(name) {
var users = new ClientManager().getUsers();
if (users.indexOf(name) === -1) {

View File

@ -8,9 +8,11 @@ var fs = require("fs");
var fsextra = require("fs-extra");
var path = require("path");
var Helper = require("../helper");
const Utils = require("./utils");
program.version(Helper.getVersion(), "-v, --version")
.option("--home <path>", `${colors.bold("[DEPRECATED]")} Use the ${colors.green("LOUNGE_HOME")} environment variable instead.`)
.on("--help", Utils.extraHelp)
.parseOptions(process.argv);
if (program.home) {
@ -21,14 +23,7 @@ if (program.home) {
let home = program.home || process.env.LOUNGE_HOME;
if (!home) {
const distConfig = path.resolve(path.join(
__dirname,
"..",
"..",
".lounge_home"
));
home = fs.readFileSync(distConfig, "utf-8").trim();
home = Utils.defaultLoungeHome();
}
Helper.setHome(home);

View File

@ -3,10 +3,12 @@
var ClientManager = new require("../clientManager");
var program = require("commander");
var colors = require("colors/safe");
const Utils = require("./utils");
program
.command("list")
.description("List all users")
.on("--help", Utils.extraHelp)
.action(function() {
var users = new ClientManager().getUsers();
if (!users.length) {

View File

@ -3,10 +3,12 @@
var ClientManager = new require("../clientManager");
var program = require("commander");
var colors = require("colors/safe");
const Utils = require("./utils");
program
.command("remove <name>")
.description("Remove an existing user")
.on("--help", Utils.extraHelp)
.action(function(name) {
var manager = new ClientManager();
if (manager.removeUser(name)) {

View File

@ -5,10 +5,12 @@ var fs = require("fs");
var program = require("commander");
var colors = require("colors/safe");
var Helper = require("../helper");
const Utils = require("./utils");
program
.command("reset <name>")
.description("Reset user password")
.on("--help", Utils.extraHelp)
.action(function(name) {
var users = new ClientManager().getUsers();
if (users.indexOf(name) === -1) {

View File

@ -5,6 +5,7 @@ var program = require("commander");
var colors = require("colors/safe");
var server = require("../server");
var Helper = require("../helper");
const Utils = require("./utils");
program
.command("start")
@ -14,6 +15,7 @@ program
.option(" --public", "start in public mode")
.option(" --private", "start in private mode")
.description("Start the server")
.on("--help", Utils.extraHelp)
.action(function(options) {
var users = new ClientManager().getUsers();

38
src/command-line/utils.js Normal file
View File

@ -0,0 +1,38 @@
"use strict";
const colors = require("colors/safe");
const fs = require("fs");
const path = require("path");
let loungeHome;
class Utils {
static extraHelp() {
[
"",
"",
" Environment variable:",
"",
` LOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(Utils.defaultLoungeHome())}.`,
"",
].forEach((e) => console.log(e));
}
static defaultLoungeHome() {
if (loungeHome) {
return loungeHome;
}
const distConfig = path.resolve(path.join(
__dirname,
"..",
"..",
".lounge_home"
));
loungeHome = fs.readFileSync(distConfig, "utf-8").trim();
return loungeHome;
}
}
module.exports = Utils;