Skip to content

Commit f46daf0

Browse files
authored
refactor: remove unnecessary no prefix options and move default values (#102)
1 parent 206ef98 commit f46daf0

1 file changed

Lines changed: 7 additions & 31 deletions

File tree

src/cli/parse-args.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function parseArgs(): Promise<ParsedArgs> {
3636
sign: args.sign,
3737
push: args.push,
3838
all: args.all,
39-
noGitCheck: args.noGitCheck,
39+
noGitCheck: args.gitCheck === undefined ? undefined : !args.gitCheck,
4040
confirm: args.yes === undefined ? undefined : !args.yes,
4141
noVerify: args.verify === undefined ? undefined : !args.verify,
4242
install: args.install,
@@ -79,17 +79,15 @@ export function loadCliArgs(argv = process.argv) {
7979
.usage('[...files]')
8080
.option('--preid <preid>', 'ID for prerelease')
8181
.option('-a, --all', `Include all files (default: ${bumpConfigDefaults.all})`)
82-
.option('--no-git-check', `Skip git check`, { default: bumpConfigDefaults.noGitCheck })
83-
.option('-c, --commit [msg]', 'Commit message', { default: true })
84-
.option('--no-commit', 'Skip commit', { default: false })
85-
.option('-t, --tag [tag]', 'Tag name', { default: true })
86-
.option('--no-tag', 'Skip tag', { default: false })
82+
.option('--git-check', `Run git check (default: ${!bumpConfigDefaults.noGitCheck})`)
83+
.option('-c, --commit [msg]', `Commit message (default: ${bumpConfigDefaults.commit})`)
84+
.option('-t, --tag [tag]', `Tag name (default: ${bumpConfigDefaults.tag})`)
8785
.option('--sign', 'Sign commit and tag')
88-
.option('--install', `Run 'npm install' after bumping version (default: ${bumpConfigDefaults.install})`, { default: false })
86+
.option('--install', `Run 'npm install' after bumping version (default: ${bumpConfigDefaults.install})`)
8987
.option('-p, --push', `Push to remote (default: ${bumpConfigDefaults.push})`)
9088
.option('-y, --yes', `Skip confirmation (default: ${!bumpConfigDefaults.confirm})`)
9189
.option('-r, --recursive', `Bump package.json files recursively (default: ${bumpConfigDefaults.recursive})`)
92-
.option('--no-verify', 'Skip git verification')
90+
.option('--verify', `Run git verification (default: ${!bumpConfigDefaults.noVerify})`)
9391
.option('--ignore-scripts', `Ignore scripts (default: ${bumpConfigDefaults.ignoreScripts})`)
9492
.option('-q, --quiet', 'Quiet mode')
9593
.option('--current-version <version>', 'Current version')
@@ -99,32 +97,10 @@ export function loadCliArgs(argv = process.argv) {
9997
.help()
10098

10199
const result = cli.parse(argv)
102-
const rawArgs = cli.rawArgs
103100
const args = result.options
104101

105-
// TODO: To simplify the checks here, should we move the default value declaration to config.ts/bumpConfigDefaults?
106-
const COMMIT_REG = /(?:-c|--commit|--no-commit)(?:=.*|$)/
107-
const TAG_REG = /(?:-t|--tag|--no-tag)(?:=.*|$)/
108-
const YES_REG = /(?:-y|--yes)(?:=.*|$)/
109-
const NO_VERIFY_REG = /--no-verify(?:=.*|$)/
110-
const INSTALL_ARG = /--install(?:=.*|$)/
111-
const hasCommitFlag = rawArgs.some(arg => COMMIT_REG.test(arg))
112-
const hasTagFlag = rawArgs.some(arg => TAG_REG.test(arg))
113-
const hasYesFlag = rawArgs.some(arg => YES_REG.test(arg))
114-
const hasNoVerifyFlag = rawArgs.some(arg => NO_VERIFY_REG.test(arg))
115-
const hasInstallFlag = rawArgs.some(arg => INSTALL_ARG.test(arg))
116-
117-
const { tag, commit, yes, ...rest } = args
118-
119102
return {
120-
args: {
121-
...rest,
122-
commit: hasCommitFlag ? commit : undefined,
123-
tag: hasTagFlag ? tag : undefined,
124-
yes: hasYesFlag ? yes : undefined,
125-
verify: hasNoVerifyFlag ? !args.verify : undefined,
126-
install: hasInstallFlag ? !args.install : undefined,
127-
} as { [k: string]: any },
103+
args,
128104
resultArgs: result.args,
129105
}
130106
}

0 commit comments

Comments
 (0)