Repository: oclif/core
Pull request #733 (2023-07-13 15:42:31)

fix: correctly print help when only command found and passed with help
@W-13753346@
https://github.com/forcedotcom/cli/issues/2301


Patch:
diff --git a/package.json b/package.json
index ca66ea6..8f92307 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "@oclif/core",
   "description": "base library for oclif CLIs",
-  "version": "2.9.2",
+  "version": "2.9.3",
   "author": "Salesforce",
   "bugs": "https://github.com/oclif/core/issues",
   "dependencies": {
diff --git a/src/help/index.ts b/src/help/index.ts
index d5572dc..e7fe823 100644
--- a/src/help/index.ts
+++ b/src/help/index.ts
@@ -124,7 +124,11 @@ export class Help extends HelpBase {
     if (this.config.flexibleTaxonomy) {
       const matches = this.config.findMatches(subject, originalArgv)
       if (matches.length > 0) {
-        const result = await this.config.runHook('command_incomplete', {id: subject, argv: originalArgv, matches})
+        const result = await this.config.runHook('command_incomplete', {
+          id: subject,
+          argv: originalArgv.filter(o => !subject.split(':').includes(o)),
+          matches,
+        })
         if (result.successes.length > 0) return
       }
     }
diff --git a/src/parser/parse.ts b/src/parser/parse.ts
index 2d83b37..b3aa0c1 100644
--- a/src/parser/parse.ts
+++ b/src/parser/parse.ts
@@ -351,10 +351,9 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
     }
 
     const flagTokenMap = this.mapAndValidateFlags()
-
     const flagsWithValues = await Promise.all(Object.entries(this.input.flags)
     // we check them if they have a token, or might have env, default, or defaultHelp.  Also include booleans so they get their default value
-    .filter(([name, flag]) => flag.type === 'boolean' || flag.env || flag.default || 'defaultHelp' in flag || flagTokenMap.has(name))
+    .filter(([name, flag]) => flag.type === 'boolean' || flag.env || flag.default !== undefined || 'defaultHelp' in flag || flagTokenMap.has(name))
     // match each possible flag to its token, if there is one
     .map(([name, flag]): FlagWithStrategy => ({inputFlag: {name, flag}, tokens: flagTokenMap.get(name)}))
     .map(fws => addValueFunction(fws))


Test patch:
diff --git a/test/parser/parse.test.ts b/test/parser/parse.test.ts
index e65f80a..c124693 100644
--- a/test/parser/parse.test.ts
+++ b/test/parser/parse.test.ts
@@ -971,6 +971,25 @@ See more help with --help`)
       expect(out.args).to.deep.include({baz: false})
     })
 
+    it('accepts falsy flags', async () => {
+      const out = await parse([], {
+        flags: {
+          foo1: Flags.string({default: ''}),
+          foo2: Flags.string({default: '0'}),
+          foo3: Flags.string({default: 'false'}),
+          foo4: Flags.string({default: 'undefined'}),
+          bar: Flags.integer({default: 0}),
+          baz: Flags.boolean({default: false}),
+        },
+      })
+      expect(out.flags).to.deep.include({foo1: ''})
+      expect(out.flags).to.deep.include({foo2: '0'})
+      expect(out.flags).to.deep.include({foo3: 'false'})
+      expect(out.flags).to.deep.include({foo4: 'undefined'})
+      expect(out.flags).to.deep.include({bar: 0})
+      expect(out.flags).to.deep.include({baz: false})
+    })
+
     it('default as function', async () => {
       const out = await parse([], {
         args: {baz: Args.string({default: async () => 'BAZ'})},