Skip to content

Commit

Permalink
Merge pull request #218 from linthtml/feat/print_config_accept_config…
Browse files Browse the repository at this point in the history
…_path

[FEAT] Print config command no longer use the config option value
  • Loading branch information
KamiKillertO committed Aug 3, 2020
2 parents 134286a + 492acc8 commit e57bb33
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/cli/index.js
Expand Up @@ -15,6 +15,7 @@ const EXIT_CODE_NORMAL = 0;

const pkg = require("../../package.json");
const printErrors = require("./print-errors");
const { find_local_config } = require("../read-config");

const cliOptions = {
help: chalk`
Expand Down Expand Up @@ -45,7 +46,7 @@ const cliOptions = {
default: true
},
"print-config": {
type: "boolean"
type: "string"
},
init: {
type: "boolean"
Expand All @@ -65,7 +66,6 @@ module.exports = (argv) => {
cliOptions.argv = argv;
const cli = meow(cliOptions);
const invalidOptionsMessage = checkInvalidCLIOptions(cliOptions.flags, cli.flags);
const config = null;
if (invalidOptionsMessage) {
process.stderr.write(invalidOptionsMessage);
return exitProcess();
Expand All @@ -76,17 +76,21 @@ module.exports = (argv) => {
.then(exitProcess);
}

if (cli.flags.config !== undefined) {
if (cli.flags.config === "") {
console.log(chalk`A file path must be provided when using the {blue.bold config} option.`);
if (cli.flags.printConfig !== undefined) {
if (cli.flags.printConfig === "") {
console.log(chalk`A file path must be provided when using the {blue.bold print-config} option.`);
process.exit(EXIT_CODE_ERROR); // eslint-disable-line no-process-exit
}
const config = find_local_config(cli.flags.printConfig);
if (config) {
process.stdout.write(JSON.stringify(config.config, null, " "));
exitProcess();
}
console.log("Couldn't file a config file to print");
exitProcess(true);
}

// use config_path if provided or search local config file
if (cli.flags.printConfig) {
process.stdout.write(JSON.stringify(config, null, " "));
}

if (cli.flags.help || cli.flags.h || argv.length === 0) {
cli.showHelp();
Expand Down

0 comments on commit e57bb33

Please sign in to comment.