Read default LOUNGE_HOME from .lounge_home file

This commit is contained in:
Jérémie Astori 2017-08-21 02:03:40 -04:00
parent 98bfe349d9
commit ac3ce74343
No known key found for this signature in database
GPG key ID: B9A4F245CD67BDE8
2 changed files with 22 additions and 9 deletions

View file

@ -23,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

@ -1,6 +1,10 @@
"use strict";
const colors = require("colors/safe");
const fs = require("fs");
const path = require("path");
let loungeHome;
class Utils {
static extraHelp() {
@ -9,10 +13,26 @@ class Utils {
"",
" Environment variable:",
"",
` LOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green("~/.lounge")}.`,
` 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;