Skip to content

Commit 0c600cf

Browse files
Merge pull request #625 from salesforcecli/sm/alias-warning
feat: warning about alias with spaces
2 parents 0782abf + ec76882 commit 0c600cf

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

messages/alias.set.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Set one or more aliases on your local computer.
44

55
# description
66

7-
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.
7+
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.
88

99
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.
1010

@@ -35,3 +35,9 @@ You must provide one or more aliases to set. Use the --help flag to see examples
3535
# error.ValueRequired
3636

3737
You must provide a value when setting an alias. Use `sf alias unset my-alias-name` to remove existing aliases.
38+
39+
# warning.spaceAlias
40+
41+
The alias "%s" includes a space. We recommend aliases without spaces.
42+
43+
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".

src/commands/alias/set.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export default class AliasSet extends AliasCommand<AliasResults> {
3434
const results = await Promise.all(
3535
Object.entries(parsed).map(async ([alias, value]) => {
3636
try {
37+
if (alias.includes(' ')) {
38+
this.warn(messages.getMessage('warning.spaceAlias', [alias, alias]));
39+
}
3740
// to support plugin-settings in sfdx, which allowed setting an alias to undefined, when that happens we'll unset the alias
3841
// which is what the user wants
3942
if (!value) {

test/commands/alias/set.nut.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ describe('alias set NUTs', () => {
6666
expect(result).to.deep.equal([{ alias: 'foo', success: true, value: 'alias with spaces' }]);
6767
});
6868

69+
it('alias set with spaces in alias (produces warning)', () => {
70+
const value = 'bar';
71+
const result = execCmd(`alias set "foo with space"=${value} --json`, {
72+
ensureExitCode: 0,
73+
}).jsonOutput;
74+
75+
expect(result?.result).to.deep.equal([{ alias: 'foo with space', success: true, value }]);
76+
expect(result?.warnings).to.deep.equal([
77+
messages.getMessage('warning.spaceAlias', ['foo with space', 'foo with space']),
78+
]);
79+
});
80+
6981
it('allow setting a single alias without an equal sign', () => {
7082
const result = execCmd('alias set theKey theValue --json', {
7183
ensureExitCode: 0,

0 commit comments

Comments
 (0)