hardlounge/src/command-line/users/edit.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

"use strict";
2018-06-15 20:31:06 +00:00
const log = require("../../log");
const program = require("commander");
const child = require("child_process");
2018-03-02 18:28:54 +00:00
const colors = require("chalk");
const fs = require("fs");
const Config = require("../../config");
const Utils = require("../utils");
2014-08-26 18:00:12 +00:00
2014-08-25 00:19:03 +00:00
program
.command("edit <name>")
.description(`Edit user file located at ${colors.green(Config.getUserConfigPath("<name>"))}`)
.on("--help", Utils.extraHelp)
.action(function (name) {
if (!fs.existsSync(Config.getUsersPath())) {
log.error(`${Config.getUsersPath()} does not exist.`);
return;
}
const ClientManager = require("../../clientManager");
const users = new ClientManager().getUsers();
2019-07-17 09:33:59 +00:00
if (users === undefined) {
// There was an error, already logged
return;
}
if (!users.includes(name)) {
log.error(`User ${colors.bold(name)} does not exist.`);
2014-08-25 00:19:03 +00:00
return;
}
2018-01-11 11:33:36 +00:00
const child_spawn = child.spawn(
process.env.EDITOR || "vi",
[Config.getUserConfigPath(name)],
2014-08-25 00:19:03 +00:00
{stdio: "inherit"}
);
child_spawn.on("error", function () {
2019-07-17 09:33:59 +00:00
log.error(
`Unable to open ${colors.green(Config.getUserConfigPath(name))}. ${colors.bold(
2019-07-17 09:33:59 +00:00
"$EDITOR"
)} is not set, and ${colors.bold("vi")} was not found.`
);
});
2014-08-25 00:19:03 +00:00
});