2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2017-07-18 11:36:24 +02:00
|
|
|
const program = require("commander");
|
|
|
|
const child = require("child_process");
|
|
|
|
const colors = require("colors/safe");
|
|
|
|
const fs = require("fs");
|
|
|
|
const Helper = require("../helper");
|
2017-08-21 07:49:32 +02:00
|
|
|
const Utils = require("./utils");
|
2014-08-19 03:53:17 +02:00
|
|
|
|
|
|
|
program
|
|
|
|
.command("config")
|
2017-12-07 04:54:54 +01:00
|
|
|
.description(`Edit configuration file located at ${colors.green(Helper.getConfigPath())}.`)
|
2017-08-21 07:49:32 +02:00
|
|
|
.on("--help", Utils.extraHelp)
|
2014-08-19 03:53:17 +02:00
|
|
|
.action(function() {
|
2017-12-07 04:54:54 +01:00
|
|
|
if (!fs.existsSync(Helper.getConfigPath())) {
|
|
|
|
log.error(`${Helper.getConfigPath()} does not exist.`);
|
2017-07-18 11:36:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 12:33:36 +01:00
|
|
|
const child_spawn = child.spawn(
|
2014-10-09 14:40:16 +02:00
|
|
|
process.env.EDITOR || "vi",
|
2017-12-07 04:54:54 +01:00
|
|
|
[Helper.getConfigPath()],
|
2014-08-19 03:53:17 +02:00
|
|
|
{stdio: "inherit"}
|
|
|
|
);
|
2016-09-20 07:33:09 +02:00
|
|
|
child_spawn.on("error", function() {
|
2017-12-07 04:54:54 +01:00
|
|
|
log.error(`Unable to open ${colors.green(Helper.getConfigPath())}. ${colors.bold("$EDITOR")} is not set, and ${colors.bold("vi")} was not found.`);
|
2016-09-20 07:33:09 +02:00
|
|
|
});
|
2014-08-19 03:53:17 +02:00
|
|
|
});
|