thelounge/src/command-line/config.js
Jérémie Astori 0482747781
Only use helpers and not shared variables around path helpers
This refactor has a few benefits, for example there cannot be a rogue update of `Helper.CONFIG_PATH` or something.
2017-12-07 23:02:32 -05:00

29 lines
849 B
JavaScript

"use strict";
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
.command("config")
.description(`Edit configuration file located at ${colors.green(Helper.getConfigPath())}.`)
.on("--help", Utils.extraHelp)
.action(function() {
if (!fs.existsSync(Helper.getConfigPath())) {
log.error(`${Helper.getConfigPath()} does not exist.`);
return;
}
var child_spawn = child.spawn(
process.env.EDITOR || "vi",
[Helper.getConfigPath()],
{stdio: "inherit"}
);
child_spawn.on("error", function() {
log.error(`Unable to open ${colors.green(Helper.getConfigPath())}. ${colors.bold("$EDITOR")} is not set, and ${colors.bold("vi")} was not found.`);
});
});