Repository: oclif/core
Pull request #164 (2021-05-17 16:05:44)

fix: conversion of spaced commands to colon commands
Fixes issue with attempting to convert a colon'd command string into spaced command string


Patch:
diff --git a/src/help/index.ts b/src/help/index.ts
index 37426b8..aa861c5 100644
--- a/src/help/index.ts
+++ b/src/help/index.ts
@@ -9,9 +9,9 @@ import {renderList} from './list'
 import RootHelp from './root'
 import {stdtermwidth} from '../screen'
 import {compact, sortBy, uniqBy} from '../util'
-import {standarizeIDFromArgv, template} from './util'
+import {standardizeIDFromArgv, template} from './util'
 
-export {standarizeIDFromArgv, getHelpClass} from './util'
+export {standardizeIDFromArgv, getHelpClass} from './util'
 
 const wrap = require('wrap-ansi')
 const {
@@ -94,7 +94,7 @@ export class Help extends HelpBase {
   }
 
   public showHelp(argv: string[]) {
-    if (this.config.topicSeparator !== ':') argv = standarizeIDFromArgv(argv, this.config)
+    if (this.config.topicSeparator !== ':') argv = standardizeIDFromArgv(argv, this.config)
     const subject = getHelpSubject(argv)
     if (!subject) {
       if (this.config.pjson.oclif.default) {
diff --git a/src/help/util.ts b/src/help/util.ts
index 3300a4c..35fe99b 100644
--- a/src/help/util.ts
+++ b/src/help/util.ts
@@ -85,7 +85,7 @@ export function toConfiguredId(commandID: string, config: IConfig): string {
   return commandID.replace(new RegExp(':', 'g'), config.topicSeparator)
 }
 
-export function standarizeIDFromArgv(argv: string[], config: IConfig): string[] {
+export function standardizeIDFromArgv(argv: string[], config: IConfig): string[] {
   if (argv.length === 0) return argv
   if (config.topicSeparator === ' ') argv = collateSpacedCmdIDFromArgs(argv, config)
   else if (config.topicSeparator !== ':') argv[0] = toStandardizedId(argv[0], config)
diff --git a/src/main.ts b/src/main.ts
index 6db42f2..aa7325d 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -2,7 +2,7 @@ import {format, inspect} from 'util'
 
 import * as Interfaces from './interfaces'
 import {Config} from './config'
-import {getHelpClass, standarizeIDFromArgv} from './help'
+import {getHelpClass, standardizeIDFromArgv} from './help'
 
 const log = (message = '', ...args: any[]) => {
   // tslint:disable-next-line strict-type-predicates
@@ -28,9 +28,9 @@ export async function run(argv = process.argv.slice(2), options?: Interfaces.Loa
   // return Main.run(argv, options)
   const config = await Config.load(options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) as Config
 
-  // run init hook
-  if (config.topicSeparator !== ':') argv = standarizeIDFromArgv(argv, config)
+  if (config.topicSeparator !== ':' && !argv[0].includes(':')) argv = standardizeIDFromArgv(argv, config)
   let [id, ...argvSlice] = argv
+  // run init hook
   await config.runHook('init', {id, argv: argvSlice})
 
   // display version if applicable


Test patch:
diff --git a/test/help/util.test.ts b/test/help/util.test.ts
index 5ea2fa0..542902c 100644
--- a/test/help/util.test.ts
+++ b/test/help/util.test.ts
@@ -2,7 +2,7 @@
 import {resolve} from 'path'
 import {Config, Interfaces} from '../../src'
 import {expect, test} from '@oclif/test'
-import {getHelpClass, standarizeIDFromArgv} from '../../src/help'
+import {getHelpClass, standardizeIDFromArgv} from '../../src/help'
 import configuredHelpClass from  '../../src/help/_test-help-class'
 
 describe('util', () => {
@@ -42,11 +42,11 @@ describe('util', () => {
     })
   })
 
-  describe('#standarizeIDFromArgv', () => {
+  describe('#standardizeIDFromArgv', () => {
     test
     .it('should return standardized id when topic separator is a colon', () => {
       config.pjson.oclif.topicSeparator = ':'
-      const actual = standarizeIDFromArgv(['foo:bar', '--baz'], config)
+      const actual = standardizeIDFromArgv(['foo:bar', '--baz'], config)
       expect(actual).to.deep.equal(['foo:bar', '--baz'])
     })
 
@@ -54,7 +54,7 @@ describe('util', () => {
     .stub(Config.prototype, 'commandIDs', () => ['foo', 'foo:bar'])
     .it('should return standardized id when topic separator is a space', () => {
       config.topicSeparator = ' '
-      const actual = standarizeIDFromArgv(['foo', 'bar', '--baz'], config)
+      const actual = standardizeIDFromArgv(['foo', 'bar', '--baz'], config)
       expect(actual).to.deep.equal(['foo:bar', '--baz'])
     })
 
@@ -62,7 +62,7 @@ describe('util', () => {
     .stub(Config.prototype, 'commandIDs', () => ['foo', 'foo:bar'])
     .it('should return standardized id when topic separator is a space and command is misspelled', () => {
       config.topicSeparator = ' '
-      const actual = standarizeIDFromArgv(['foo', 'ba', '--baz'], config)
+      const actual = standardizeIDFromArgv(['foo', 'ba', '--baz'], config)
       expect(actual).to.deep.equal(['foo:ba', '--baz'])
     })
   })