Skip to content

Commit

Permalink
fix(cli): restore original options array
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 8, 2020
1 parent 00304bc commit 0d398a9
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 81 deletions.
164 changes: 84 additions & 80 deletions @commitlint/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import load from '@commitlint/load';
import lint from '@commitlint/lint';
import read from '@commitlint/read';
import merge from 'lodash/merge';
import isFunction from 'lodash/isFunction';
import stdin from 'get-stdin';
import resolveFrom from 'resolve-from';
Expand All @@ -21,81 +20,83 @@ import {
const pkg = require('../package');

const cli = yargs
.option('color', {
alias: 'c',
default: true,
describe: 'toggle colored output',
type: 'boolean'
})
.option('config', {
alias: 'g',
describe: 'path to the config file',
type: 'string'
})
.option('cwd', {
alias: 'd',
default: process.cwd(),
describe: 'directory to execute in',
type: 'string'
})
.option('edit', {
alias: 'e',
// default: false,
describe:
'read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG',
type: 'string'
})
.option('env', {
alias: 'E',
describe:
'check message in the file at path given by environment variable value',
type: 'string'
})
.option('extends', {
alias: 'x',
describe: 'array of shareable configurations to extend',
type: 'array'
})
.option('help-url', {
alias: 'H',
type: 'string',
describe: 'helpurl in error message'
})
.option('from', {
alias: 'f',
describe: 'lower end of the commit range to lint; applies if edit=false',
type: 'string'
})
.option('format', {
alias: 'o',
describe: 'output format of the results',
type: 'string'
})
.option('parser-preset', {
alias: 'p',
describe: 'configuration preset to use for conventional-commits-parser',
type: 'string'
})
.option('quiet', {
alias: 'q',
default: false,
describe: 'toggle console output',
type: 'boolean'
})
.option('to', {
alias: 't',
describe: 'upper end of the commit range to lint; applies if edit=false',
type: 'string'
})
.option('version', {
alias: 'v',
type: 'boolean',
describe: 'display version information'
})
.option('verbose', {
alias: 'V',
type: 'boolean',
describe: 'enable verbose output for reports without problems'
.options({
color: {
alias: 'c',
default: true,
description: 'toggle colored output',
type: 'boolean'
},
config: {
alias: 'g',
description: 'path to the config file',
type: 'string'
},
cwd: {
alias: 'd',
default: process.cwd(),
description: 'directory to execute in',
type: 'string'
},
edit: {
alias: 'e',
default: false,
description:
'read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG',
type: 'string'
},
env: {
alias: 'E',
description:
'check message in the file at path given by environment variable value',
type: 'string'
},
extends: {
alias: 'x',
description: 'array of shareable configurations to extend',
type: 'array'
},
'help-url': {
alias: 'H',
type: 'string',
description: 'helpurl in error message'
},
from: {
alias: 'f',
description: 'lower end of the commit range to lint; applies if edit=false',
type: 'string'
},
format: {
alias: 'o',
description: 'output format of the results',
type: 'string'
},
'parser-preset': {
alias: 'p',
description: 'configuration preset to use for conventional-commits-parser',
type: 'string'
},
quiet: {
alias: 'q',
default: false,
description: 'toggle console output',
type: 'boolean'
},
to: {
alias: 't',
description: 'upper end of the commit range to lint; applies if edit=false',
type: 'string'
},
version: {
alias: 'v',
type: 'boolean',
description: 'display version information'
},
verbose: {
alias: 'V',
type: 'boolean',
description: 'enable verbose output for reports without problems'
}
})
.help(
'help',
Expand Down Expand Up @@ -242,7 +243,7 @@ async function main(options: CliFlags) {
}
}

function checkFromStdin(input: string[], flags: CliFlags) {
function checkFromStdin(input: string[], flags: CliFlags): boolean {
return input.length === 0 && !checkFromRepository(flags);
}

Expand All @@ -254,13 +255,16 @@ function checkFromEdit(flags: CliFlags) {
return Boolean(flags.edit) || flags.env;
}

function checkFromHistory(flags: CliFlags) {
function checkFromHistory(flags: CliFlags): boolean {
return typeof flags.from === 'string' || typeof flags.to === 'string';
}

function normalizeFlags(flags: CliFlags) {
function normalizeFlags(flags: CliFlags): CliFlags {
const edit = getEditValue(flags);
return merge({}, flags, {edit, e: edit});
return {
...flags,
edit
};
}

function getEditValue(flags: CliFlags) {
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface CliFlags {
color: boolean;
config?: string;
cwd: string;
edit?: string;
edit?: string | boolean;
env?: string;
extends?: (string | number)[];
help?: boolean;
Expand Down

0 comments on commit 0d398a9

Please sign in to comment.