Skip to content

Commit

Permalink
fix: remove deprecated core aliasAccessor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 2, 2024
1 parent cbc7a0c commit 5e9ec8b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
42 changes: 21 additions & 21 deletions src/commands/alias/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ export default class AliasSet extends AliasCommand<AliasResults> {

const parsed = parseVarArgs(args, argv as string[]);

const results = Object.entries(parsed).map(([alias, value]) => {
try {
// 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) {
stateAggregator.aliases.unset(alias);
} else {
stateAggregator.aliases.set(alias, value);
const results = await Promise.all(
Object.entries(parsed).map(async ([alias, value]) => {
try {
// 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) {
await stateAggregator.aliases.unsetAndSave(alias);
} else {
await stateAggregator.aliases.setAndSave(alias, value);
}
return { alias, success: true, value };
} catch (err) {
const { name, message } =
err instanceof Error
? err
: typeof err === 'string'
? new Error(err)
: { name: 'UnknownError', message: 'Unknown Error' };
return { alias, success: false, error: { name, message }, value };
}
return { alias, success: true, value };
} catch (err) {
const { name, message } =
err instanceof Error
? err
: typeof err === 'string'
? new Error(err)
: { name: 'UnknownError', message: 'Unknown Error' };
return { alias, success: false, error: { name, message }, value };
}
});

await stateAggregator.aliases.write();
})
);

this.output('Alias Set', results);

Expand Down
38 changes: 20 additions & 18 deletions src/commands/alias/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,26 @@ export default class AliasUnset extends AliasCommand<AliasResults> {
return [];
}

const results = toRemove.map((alias) => {
// We will log the value in the output in case an alias was unset by mistake.
const value = aliases[alias];
try {
stateAggregator.aliases.unset(alias);
return { alias, value, success: true };
} catch (err) {
const { name, message } =
err instanceof Error
? err
: typeof err === 'string'
? new Error(err)
: { name: 'UnknownError', message: 'Unknown Error' };
return { alias, value, success: false, error: { name, message } };
}
});

await stateAggregator.aliases.write();
const results = await Promise.all(
toRemove
// We will log the value in the output in case an alias was unset by mistake.
.map((alias) => ({ alias, value: aliases[alias] }))
.map(async ({ alias, value }) => {
try {
// safe to parallelize because of file locking
await stateAggregator.aliases.unsetAndSave(alias);
return { alias, value, success: true };
} catch (err) {
const { name, message } =
err instanceof Error
? err
: typeof err === 'string'
? new Error(err)
: { name: 'UnknownError', message: 'Unknown Error' };
return { alias, value, success: false, error: { name, message } };
}
})
);

this.output('Alias Unset', results);

Expand Down

0 comments on commit 5e9ec8b

Please sign in to comment.