From 5339a3c869b856c92984a6d30631d518e1335f56 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 2 Feb 2026 13:58:33 -0800 Subject: [PATCH 1/2] feat(help): show --version in help output Also fixes --version to always exit (with code 0) even when version detection fails, preventing confusing parse errors. Note: Testing --version/--help behavior is intentionally excluded from coverage as these paths call process.exit(). --- src/bargs.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bargs.ts b/src/bargs.ts index 4867786..153a511 100644 --- a/src/bargs.ts +++ b/src/bargs.ts @@ -860,8 +860,9 @@ const parseCore = ( const version = detectVersionSync(options.version); if (version) { console.log(version); - process.exit(0); } + // Always exit when --version is passed (even if version unavailable) + process.exit(0); } // Handle shell completion (when enabled) @@ -1004,8 +1005,19 @@ const generateCommandHelpNew = ( */ /* c8 ignore start -- only called from help paths that call process.exit() */ const generateHelpNew = (state: InternalCliState, theme: Theme): string => { - // Build options schema, adding --completion-script if completion is enabled + // Build options schema, adding built-in options let options = state.globalParser?.__optionsSchema; + + // Always add --version (it's always available, even if detection might fail) + options = { + ...options, + version: { + description: 'Show version number', + type: 'boolean' as const, + }, + }; + + // Add --completion-script if completion is enabled if (state.options.completion) { options = { ...options, From 3d0b3a846c65c44128e3b1294cee613378b28c41 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Tue, 3 Feb 2026 15:09:17 -0800 Subject: [PATCH 2/2] fix: address review feedback - Add --help to help output for consistency with --version - Print 'Version information not available' when version detection fails --- src/bargs.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bargs.ts b/src/bargs.ts index 153a511..3227ba8 100644 --- a/src/bargs.ts +++ b/src/bargs.ts @@ -860,8 +860,9 @@ const parseCore = ( const version = detectVersionSync(options.version); if (version) { console.log(version); + } else { + console.log('Version information not available'); } - // Always exit when --version is passed (even if version unavailable) process.exit(0); } @@ -1008,9 +1009,14 @@ const generateHelpNew = (state: InternalCliState, theme: Theme): string => { // Build options schema, adding built-in options let options = state.globalParser?.__optionsSchema; - // Always add --version (it's always available, even if detection might fail) + // Always add --help and --version (they're always available) options = { ...options, + help: { + aliases: ['h'], + description: 'Show help information', + type: 'boolean' as const, + }, version: { description: 'Show version number', type: 'boolean' as const,