Skip to content

Commit

Permalink
fix: args parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 16, 2022
1 parent 3faeba3 commit 0670925
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 94 deletions.
2 changes: 1 addition & 1 deletion bin/bumpp.js
@@ -1,4 +1,4 @@
#!/usr/bin/env node
'use strict'
const { main } = require('../dist/cli')
main(process.argv.slice(2))
main()
83 changes: 0 additions & 83 deletions src/cli/help.ts

This file was deleted.

7 changes: 2 additions & 5 deletions src/cli/index.ts
Expand Up @@ -4,26 +4,23 @@ import type { VersionBumpProgress } from '../types/version-bump-progress'
import { ProgressEvent } from '../types/version-bump-progress'
import { versionBump } from '../version-bump'
import { ExitCode } from './exit-code'
import { helpText } from './help'
import { parseArgs } from './parse-args'

/**
* The main entry point of the CLI
*
* @param args - The command-line arguments (e.g. ["major", "--preid=alpha", "-ctpa"])
*/
export async function main(args: string[]): Promise<void> {
export async function main(): Promise<void> {
try {
// Setup global error handlers
process.on('uncaughtException', errorHandler)
process.on('unhandledRejection', errorHandler)

// Parse the command-line arguments
const { help, version, quiet, options } = parseArgs(args)
const { help, version, quiet, options } = parseArgs()

if (help) {
// Show the help text and exit
console.log(helpText)
process.exit(ExitCode.Success)
}
else if (version) {
Expand Down
7 changes: 3 additions & 4 deletions src/cli/parse-args.ts
Expand Up @@ -4,7 +4,6 @@ import { isReleaseType } from '../release-type'
import type { VersionBumpOptions } from '../types/version-bump-options'
import { version } from '../../package.json'
import { ExitCode } from './exit-code'
import { usageText } from './help'

/**
* The parsed command-line arguments
Expand All @@ -19,7 +18,7 @@ export interface ParsedArgs {
/**
* Parses the command-line arguments
*/
export function parseArgs(argv: string[]): ParsedArgs {
export function parseArgs(): ParsedArgs {
try {
const cli = cac('bumpp')

Expand All @@ -39,7 +38,8 @@ export function parseArgs(argv: string[]): ParsedArgs {
.option('-x, --execute <command>', 'Commands to execute after version bumps')
.help()

const args = cli.parse(argv).options
const result = cli.parse()
const args = result.options

const parsedArgs: ParsedArgs = {
help: args.help as boolean,
Expand Down Expand Up @@ -79,6 +79,5 @@ export function parseArgs(argv: string[]): ParsedArgs {

function errorHandler(error: Error): never {
console.error(error.message)
console.error(usageText)
return process.exit(ExitCode.InvalidArgument)
}
2 changes: 1 addition & 1 deletion src/cli/run.ts
@@ -1,3 +1,3 @@
import { main } from '.'

main(process.argv.slice(2))
main()

0 comments on commit 0670925

Please sign in to comment.