fix(parse-args): add helpful -r flag deprecation error message

This commit is contained in:
Todd Bluhm 2025-07-12 01:14:31 -08:00
parent 592ad064fb
commit e2db12b878
No known key found for this signature in database
GPG Key ID: 9CF312607477B8AB
2 changed files with 11 additions and 2 deletions

6
dist/parse-args.js vendored
View File

@ -1,4 +1,4 @@
import { Command } from '@commander-js/extra-typings';
import { Command, Option, CommanderError } from '@commander-js/extra-typings';
import { parseArgList } from './utils.js';
import packageJson from '../package.json' with { type: 'json' };
/**
@ -89,6 +89,10 @@ export function parseArgsUsingCommander(args) {
.option('--silent', 'Ignore any env-cmd errors and only fail on executed program failure.')
.option('--use-shell', 'Execute the command in a new shell with the given environment')
.option('--verbose', 'Print helpful debugging information')
// TODO: Remove -r deprecation error on version >= v12
.addOption(new Option('-r, --rc-file [path]', 'Deprecated Option')
.hideHelp()
.argParser(() => { throw new CommanderError(1, 'deprecated-option', 'The -r flag has been deprecated, use the -f flag instead.'); }))
.allowUnknownOption(true)
.allowExcessArguments(true)
.parse(['_', '_', ...args], { from: 'node' });

View File

@ -1,4 +1,4 @@
import { Command } from '@commander-js/extra-typings'
import { Command, Option, CommanderError } from '@commander-js/extra-typings'
import type { EnvCmdOptions, CommanderOptions, EnvFileOptions, RCFileOptions } from './types.ts'
import { parseArgList } from './utils.js'
import packageJson from '../package.json' with { type: 'json' }
@ -88,6 +88,7 @@ export function parseArgs(args: string[]): EnvCmdOptions {
}
export function parseArgsUsingCommander(args: string[]): CommanderOptions {
return new Command('env-cmd')
.description('CLI for executing commands using an environment from an env file.')
.version(packageJson.version, '-v, --version')
@ -100,6 +101,10 @@ export function parseArgsUsingCommander(args: string[]): CommanderOptions {
.option('--silent', 'Ignore any env-cmd errors and only fail on executed program failure.')
.option('--use-shell', 'Execute the command in a new shell with the given environment')
.option('--verbose', 'Print helpful debugging information')
// TODO: Remove -r deprecation error on version >= v12
.addOption(new Option('-r, --rc-file [path]', 'Deprecated Option')
.hideHelp()
.argParser(() => { throw new CommanderError(1, 'deprecated-option', 'The -r flag has been deprecated, use the -f flag instead.') }))
.allowUnknownOption(true)
.allowExcessArguments(true)
.parse(['_', '_', ...args], { from: 'node' })