diff --git a/messages/alias.set.md b/messages/alias.set.md index 507899ff..3c9ca822 100644 --- a/messages/alias.set.md +++ b/messages/alias.set.md @@ -4,7 +4,7 @@ Set one or more aliases on your local computer. # description -Aliases are user-defined short names that make it easier to use the CLI. For example, users often set an alias for a scratch org usernames because they're long and unintuitive. Check the --help of a CLI command to determine where you can use an alias. +Aliases are user-defined short names that make it easier to use the CLI. For example, users often set an alias for a scratch org usernames because they're long and unintuitive. Check the --help of a CLI command to determine where you can use an alias. You can associate an alias with only one value at a time. If you set an alias multiple times, the alias points to the most recent value. Aliases are global; after you set an alias, you can use it in any Salesforce DX project on your computer. @@ -35,3 +35,9 @@ You must provide one or more aliases to set. Use the --help flag to see examples # error.ValueRequired You must provide a value when setting an alias. Use `sf alias unset my-alias-name` to remove existing aliases. + +# warning.spaceAlias + +The alias "%s" includes a space. We recommend aliases without spaces. + +If you decide to keep "%s", you must wrap it in double quotes when using it in any CLI command. For example: sf project deploy start --target-org "my scratch". diff --git a/src/commands/alias/set.ts b/src/commands/alias/set.ts index 5d1f7851..b69e25be 100644 --- a/src/commands/alias/set.ts +++ b/src/commands/alias/set.ts @@ -34,6 +34,9 @@ export default class AliasSet extends AliasCommand { const results = await Promise.all( Object.entries(parsed).map(async ([alias, value]) => { try { + if (alias.includes(' ')) { + this.warn(messages.getMessage('warning.spaceAlias', [alias, alias])); + } // to support plugin-settings in sfdx, which allowed setting an alias to undefined, when that happens we'll unset the alias // which is what the user wants if (!value) { diff --git a/test/commands/alias/set.nut.ts b/test/commands/alias/set.nut.ts index ca350fa6..6f76c003 100644 --- a/test/commands/alias/set.nut.ts +++ b/test/commands/alias/set.nut.ts @@ -66,6 +66,18 @@ describe('alias set NUTs', () => { expect(result).to.deep.equal([{ alias: 'foo', success: true, value: 'alias with spaces' }]); }); + it('alias set with spaces in alias (produces warning)', () => { + const value = 'bar'; + const result = execCmd(`alias set "foo with space"=${value} --json`, { + ensureExitCode: 0, + }).jsonOutput; + + expect(result?.result).to.deep.equal([{ alias: 'foo with space', success: true, value }]); + expect(result?.warnings).to.deep.equal([ + messages.getMessage('warning.spaceAlias', ['foo with space', 'foo with space']), + ]); + }); + it('allow setting a single alias without an equal sign', () => { const result = execCmd('alias set theKey theValue --json', { ensureExitCode: 0,