Repository: oclif/core (ts)

Issue:
Warning mistakenly displayed when using a flag that starts with a deprecated alias
**Describe the bug**
While working on a Salesforce CLI plugin I ran into the following bug regarding deprecated flag warning messages.

Given a flag, `foo-bar` is added to a command and has an `alias`, `foo` and the flag is configured with `deprecateAliases: true`, when executing the command with `--foo` the deprecated flag warning message is displayed as expected.

However, when executing the command with  `--foo-bar` the deprecated flag warning message is displayed saying:
> Warning: The "--foo" flag has been deprecated. Use "--foo-bar" instead.

**To Reproduce**
Steps to reproduce the behavior:
1. Add a flag to a command with configuration as follows: 
```typescript
    'foo-bar': Flags.boolean({
      summary: 'summary',
      deprecateAliases: true,
      aliases: ['foo']
    }),
```
2.  Execute the command with flag `--foo-bar`
```
$ ./bin/dev.js mycommand --foo-bar
```
3. Warning is displayed
> Warning: The "--foo" flag has been deprecated. Use "--foo-bar" instead.

**Expected behavior**
Warning should not be displayed when `--foo-bar` flag is used as the flag is not marked as deprecated, only the alias flag `--foo` should be considered deprecated.

**Environment (please complete the following information):**
 - OS & version: Ubuntu 22.04.5 LTS
 - Shell/terminal & version zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
 
`package.json` dependencies
```json
  "dependencies": {
    "@jsforce/jsforce-node": "^3.4.1",
    "@oclif/core": "^4.0.19",
    "@salesforce/apex-node": "^8.1.4",
    "@salesforce/core": "^8.4.0",
    "@salesforce/sf-plugins-core": "^11.3.6",
    "@salesforce/ts-types": "^2.0.10"
  },
  "devDependencies": {
    "@oclif/plugin-command-snapshot": "^5.2.8",
    "@salesforce/cli-plugins-testkit": "^5.3.19",
    "@salesforce/dev-scripts": "^10.2.9",
    "@salesforce/ts-sinon": "^1.4.24",
    "@types/node": "^22.4.0",
    "@types/sinon-chai": "^3.2.12",
    "eslint": "^8.56.0",
    "eslint-plugin-sf-plugin": "^1.19.0",
    "oclif": "^4.14.8",
    "prettier": "^3.3.3",
    "pretty-quick": "^4.0.0",
    "sinon-chai": "^4.0.0",
    "ts-node": "^10.9.2",
    "typedoc": "^0.26.5",
    "typescript": "^5.4.5"
  },

```
**Additional context**
Looks like source of problem is related to use of `startsWith` on line 339.
https://github.com/oclif/core/blob/7ede2e5865b1b6515f534651b45dc59279df0716/src/command.ts#L339-L346

Pull request:
fix: deprecated aliases bug
Fix bug with `deprecateAliases` warning showing when flag name starts with deprecated alias.

**QA**
- `oclif generate my-cli`
- add this flag definition to `src/commands/hello/index.ts`
```
    'foo-bar': Flags.boolean({
      summary: 'summary',
      deprecateAliases: true,
      aliases: ['foo']
    }),
```
- checkout this branch and run `yarn build`
- `yarn link @oclif/core` in `my-cli` directory
- `bin/dev.js hello oclif --from me --foo-bar` should **not** emit warning
- `bin/dev.js hello oclif --from me --foo` should emit warning

Fixes #1204 
@W-16866149@

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62da7e6..4494af9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+## [4.0.24](https://github.com/oclif/core/compare/4.0.23...4.0.24) (2024-10-01)
+
+
+### Bug Fixes
+
+* use topic separator for deprecated alias warnings in `help` ([#1209](https://github.com/oclif/core/issues/1209)) ([fb6ace2](https://github.com/oclif/core/commit/fb6ace237c5f6b3f7707edb7ba93e00aeee9b412))
+
+
+
 ## [4.0.23](https://github.com/oclif/core/compare/4.0.22...4.0.23) (2024-09-23)
 
 
diff --git a/package.json b/package.json
index 3a1da92..1429d3f 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "@oclif/core",
   "description": "base library for oclif CLIs",
-  "version": "4.0.23",
+  "version": "4.0.24",
   "author": "Salesforce",
   "bugs": "https://github.com/oclif/core/issues",
   "dependencies": {
diff --git a/src/command.ts b/src/command.ts
index e7fab15..dbf1652 100644
--- a/src/command.ts
+++ b/src/command.ts
@@ -283,7 +283,8 @@ export abstract class Command {
     // Since config.runHook will only run the hook for the root plugin, hookResult.successes will always have a length of 0 or 1
     // But to be extra safe, we find the result that matches the root plugin.
     const argvToParse = hookResult.successes?.length
-      ? hookResult.successes.find((s) => s.plugin.root === Cache.getInstance().get('rootPlugin')?.root)?.result ?? argv
+      ? (hookResult.successes.find((s) => s.plugin.root === Cache.getInstance().get('rootPlugin')?.root)?.result ??
+        argv)
       : argv
     this.argv = [...argvToParse]
     const results = await Parser.parse<F, B, A>(argvToParse, opts)
@@ -336,7 +337,7 @@ export abstract class Command {
         )
         if (aliases.length === 0) return
 
-        const foundAliases = aliases.filter((alias) => this.argv.some((a) => a.startsWith(alias)))
+        const foundAliases = aliases.filter((alias) => this.argv.includes(alias))
         for (const alias of foundAliases) {
           let preferredUsage = `--${flagDef?.name}`
           if (flagDef?.char) {
diff --git a/src/help/index.ts b/src/help/index.ts
index ddfcb36..d3df7b9 100644
--- a/src/help/index.ts
+++ b/src/help/index.ts
@@ -201,7 +201,8 @@ export class Help extends HelpBase {
 
     if (command.deprecateAliases && command.aliases.includes(name)) {
       const actualCmd = this.config.commands.find((c) => c.aliases.includes(name))
-      const opts = {...command.deprecationOptions, ...(actualCmd ? {to: actualCmd.id} : {})}
+      const actualCmdName = actualCmd ? toConfiguredId(actualCmd.id, this.config) : ''
+      const opts = {...command.deprecationOptions, ...(actualCmd ? {to: actualCmdName} : {})}
       this.log(`${formatCommandDeprecationWarning(toConfiguredId(name, this.config), opts)}\n`)
     }
 


Test patch:
diff --git a/test/command/command.test.ts b/test/command/command.test.ts
index 3fd03cc..4b1357e 100644
--- a/test/command/command.test.ts
+++ b/test/command/command.test.ts
@@ -95,7 +95,7 @@ describe('command', () => {
     class CMD extends Command {
       static flags = {
         name: Flags.string({
-          aliases: ['username', 'target-user', 'u'],
+          aliases: ['username', 'target-user', 'u', 'nam'],
           deprecateAliases: true,
           char: 'o',
         }),
@@ -137,6 +137,11 @@ describe('command', () => {
       const {stderr} = await captureOutput(async () => CMD.run(['--name', 'u']))
       expect(stderr).to.be.empty
     })
+
+    it('shows no warning when using flag with deprecated alias that starts with the actual flag', async () => {
+      const {stderr} = await captureOutput(async () => CMD.run(['--name', 'astro']))
+      expect(stderr).to.be.empty
+    })
   })
 
   describe('deprecated flags', () => {