Repository: oclif/core
Pull request #844 (2023-10-27 14:45:32)

fix: support hasDynamicHelp for v2 commands
Support `hasDynamicHelp` for v2 commands

@W-14378871@


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 299a710..37a2e60 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+## [3.9.1](https://github.com/oclif/core/compare/3.9.0...3.9.1) (2023-10-27)
+
+
+### Bug Fixes
+
+* restore exit(0) behavior ([0c3fdd7](https://github.com/oclif/core/commit/0c3fdd7a7e3bfe605274d69894e9a2fba8c2e3d7))
+
+
+
 # [3.9.0](https://github.com/oclif/core/compare/3.8.0...3.9.0) (2023-10-26)
 
 
diff --git a/package.json b/package.json
index f1840b0..c7d9bf1 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "@oclif/core",
   "description": "base library for oclif CLIs",
-  "version": "3.9.0",
+  "version": "3.9.1",
   "author": "Salesforce",
   "bugs": "https://github.com/oclif/core/issues",
   "dependencies": {
diff --git a/src/command.ts b/src/command.ts
index 1f7e103..b93afb8 100644
--- a/src/command.ts
+++ b/src/command.ts
@@ -210,9 +210,7 @@ export abstract class Command {
     return Errors.error(input, options as any)
   }
 
-  public exit(code: number): never
-  public exit(code: 0): void
-  public exit(code = 0): void | never {
+  public exit(code = 0): never {
     Errors.exit(code)
   }
 
diff --git a/src/errors/index.ts b/src/errors/index.ts
index 873d616..ce120a5 100644
--- a/src/errors/index.ts
+++ b/src/errors/index.ts
@@ -11,10 +11,8 @@ export {ExitError} from './errors/exit'
 export {ModuleLoadError} from './errors/module-load'
 export {handle} from './handle'
 
-export function exit(code = 0) {
-  if (code !== 0) {
-    throw new ExitError(code)
-  }
+export function exit(code = 0): never {
+  throw new ExitError(code)
 }
 
 export function error(input: Error | string, options: {exit: false} & PrettyPrintableError): void
diff --git a/src/help/index.ts b/src/help/index.ts
index aeac1f6..f43f17d 100644
--- a/src/help/index.ts
+++ b/src/help/index.ts
@@ -235,7 +235,15 @@ export class Help extends HelpBase {
       if (command.hasDynamicHelp && command.pluginType !== 'jit') {
         const loaded = await command.load()
         for (const [name, flag] of Object.entries(loaded.flags)) {
-          if (flag.type === 'boolean' || !command.flags[name].hasDynamicHelp) continue
+          // As of v3 each flag that needs to be re-evaluated has the `hasDynamicHelp` property.
+          // However, we cannot assume that the absence of this property means that the flag
+          // doesn't need to be re-evaluated since any command from a v2 or older plugin will
+          // not have the `hasDynamicHelp` property on it.
+
+          // In the future we could improve performance by skipping any flag that doesn't
+          // have `hasDynamicHelp === true`
+
+          if (flag.type === 'boolean') continue
           // eslint-disable-next-line no-await-in-loop
           command.flags[name].default = await cacheDefaultValue(flag, false)
         }


Test patch:
diff --git a/test/command/command.test.ts b/test/command/command.test.ts
index c86f333..35f33ea 100644
--- a/test/command/command.test.ts
+++ b/test/command/command.test.ts
@@ -68,7 +68,8 @@ describe('command', () => {
 
       return Command.run([])
     })
-    .it('exits with 0 does not throw error')
+    .catch(/EEXIT: 0/)
+    .it('exits with 0')
 
   describe('parse', () => {
     fancy.stdout().it('has a flag', async (ctx) => {