Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: warning about alias with spaces #625

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" to always wrap it in double quotes when using it in any CLI command.
mshanemc marked this conversation as resolved.
Show resolved Hide resolved
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
Loading