Skip to content

Commit

Permalink
Merge pull request #625 from salesforcecli/sm/alias-warning
Browse files Browse the repository at this point in the history
feat: warning about alias with spaces
  • Loading branch information
WillieRuemmele authored Jun 4, 2024
2 parents 0782abf + ec76882 commit 0c600cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion messages/alias.set.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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".
3 changes: 3 additions & 0 deletions src/commands/alias/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default class AliasSet extends AliasCommand<AliasResults> {
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) {
Expand Down
12 changes: 12 additions & 0 deletions test/commands/alias/set.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0c600cf

Please sign in to comment.