Fix up commander changes

This commit is contained in:
Pavel Djundik 2020-03-15 13:53:09 +02:00
parent b000a594f4
commit 80b0e8ad12
5 changed files with 9 additions and 22 deletions

View file

@ -16,12 +16,6 @@ program
"override entries of the configuration file, must be specified for each entry that needs to be overriden",
Utils.parseConfigOptions
)
.on("command:*", () => {
log.error(
`Unknown command. See ${colors.bold("--help")} for a list of available commands.`
);
process.exit(1);
})
.on("--help", Utils.extraHelp);
// Parse options from `argv` returning `argv` void of these options.
@ -58,13 +52,9 @@ require("./outdated");
// a version of `argv` that does not contain options already parsed by
// `parseOptions` above.
// This is done by giving it the updated `argv` that `parseOptions` returned,
// except it returns an object with `args`/`unknown`, so we need to concat them.
// except it returns an object with `operands`/`unknown`, so we need to concat them.
// See https://github.com/tj/commander.js/blob/fefda77f463292/index.js#L686-L763
program.parse(argvWithoutOptions.args.concat(argvWithoutOptions.unknown));
if (program.rawArgs.length < 3) {
program.help();
}
program.parse(argvWithoutOptions.operands.concat(argvWithoutOptions.unknown));
function createPackagesFolder() {
const packagesPath = Helper.getPackagesPath();

View file

@ -8,7 +8,7 @@ const Utils = require("./utils");
program
.command("upgrade [packages...]")
.description("Upgrade installed themes and packages to their latest versions.")
.description("Upgrade installed themes and packages to their latest versions")
.on("--help", Utils.extraHelp)
.action(function(packages) {
const fs = require("fs");

View file

@ -10,7 +10,7 @@ const Utils = require("../utils");
program
.command("edit <name>")
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`)
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}`)
.on("--help", Utils.extraHelp)
.action(function(name) {
if (!fs.existsSync(Helper.getUsersPath())) {

View file

@ -13,12 +13,10 @@ class Utils {
static extraHelp() {
[
"",
"",
" Environment variable:",
"",
` THELOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(
"Environment variable:",
` THELOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(
Helper.expandHome(Utils.defaultHome())
)}.`,
)}`,
"",
].forEach((e) => log.raw(e));
}

View file

@ -19,10 +19,9 @@ describe("Utils", function() {
Utils.extraHelp();
// Starts with 2 empty lines
// Starts with 1 empty line
expect(stdout[0]).to.equal("\n");
expect(stdout[1]).to.equal("\n");
expect(stdout[2]).to.not.equal("\n");
expect(stdout[1]).to.not.equal("\n");
// Ends with 1 empty line
expect(stdout[stdout.length - 2]).to.not.equal("\n");