thelounge/src/command-line/edit.js

29 lines
929 B
JavaScript
Raw Normal View History

"use strict";
2014-08-25 02:19:03 +02:00
var ClientManager = new require("../clientManager");
var program = require("commander");
var child = require("child_process");
var colors = require("colors/safe");
var Helper = require("../helper");
const Utils = require("./utils");
2014-08-26 20:00:12 +02:00
2014-08-25 02:19:03 +02:00
program
.command("edit <name>")
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`)
.on("--help", Utils.extraHelp)
2014-08-25 02:19:03 +02:00
.action(function(name) {
var users = new ClientManager().getUsers();
if (users.indexOf(name) === -1) {
log.error(`User ${colors.bold(name)} does not exist.`);
2014-08-25 02:19:03 +02:00
return;
}
var child_spawn = child.spawn(
process.env.EDITOR || "vi",
[Helper.getUserConfigPath(name)],
2014-08-25 02:19:03 +02:00
{stdio: "inherit"}
);
child_spawn.on("error", function() {
log.error(`Unable to open ${colors.green(Helper.getUserConfigPath(name))}. ${colors.bold("$EDITOR")} is not set, and ${colors.bold("vi")} was not found.`);
});
2014-08-25 02:19:03 +02:00
});