Skip to content

Commit

Permalink
refactor: use native aliases and deprecateAliases feature (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon authored Jan 9, 2025
1 parent ce699b2 commit d0d592d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 69 deletions.
8 changes: 0 additions & 8 deletions messages/delta.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ file listing paths to explicitly include for any diff actions

file listing paths to explicitly include for any destructive actions

# flags.deprecated

/!\ deprecated, use '--%s' instead.

# error.ParameterIsNotGitSHA

--%s is not a valid sha pointer: '%s' (If in CI/CD context, check the fetch depth is properly set)
Expand All @@ -83,10 +79,6 @@ API version not found or not supported, using '%s' instead
# warning.FlowDeleted

Attempt to delete the flow '%s' via destructiveChanges.xml may not work as expected (see https://github.com/scolladon/sfdx-git-delta#handle-flow-deletion)

# warning.oldParameters

Using the '--%s' parameter is deprecated and will soon be obsolete. Use '--%s' parameter instead.

# info.CommandIsRunning

Expand Down
75 changes: 14 additions & 61 deletions src/commands/sgd/source/delta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
TO_DEFAULT_VALUE,
} from '../../../utils/cliConstants.js'

import { camelCase } from 'lodash-es'

const messages = new MessageService()

export default class SourceDeltaGenerate extends SfCommand<SgdResult> {
Expand Down Expand Up @@ -41,38 +39,52 @@ export default class SourceDeltaGenerate extends SfCommand<SgdResult> {
summary: messages.getMessage('flags.output.summary'),
default: OUTPUT_DEFAULT_VALUE,
exists: true,
aliases: ['output'],
deprecateAliases: true,
}),
'repo-dir': Flags.directory({
char: 'r',
summary: messages.getMessage('flags.repo.summary'),
default: REPO_DEFAULT_VALUE,
exists: true,
aliases: ['repo'],
deprecateAliases: true,
}),
'source-dir': Flags.directory({
char: 's',
summary: messages.getMessage('flags.source.summary'),
default: SOURCE_DEFAULT_VALUE,
exists: true,
aliases: ['source'],
deprecateAliases: true,
}),
'ignore-file': Flags.file({
char: 'i',
summary: messages.getMessage('flags.ignore.summary'),
exists: true,
aliases: ['ignore'],
deprecateAliases: true,
}),
'ignore-destructive-file': Flags.file({
char: 'D',
summary: messages.getMessage('flags.ignore-destructive.summary'),
exists: true,
aliases: ['ignore-destructive'],
deprecateAliases: true,
}),
'include-file': Flags.file({
char: 'n',
summary: messages.getMessage('flags.include.summary'),
exists: true,
aliases: ['include'],
deprecateAliases: true,
}),
'include-destructive-file': Flags.file({
char: 'N',
summary: messages.getMessage('flags.include-destructive.summary'),
exists: true,
aliases: ['include-destructive'],
deprecateAliases: true,
}),
'ignore-whitespace': Flags.boolean({
char: 'W',
Expand All @@ -82,39 +94,6 @@ export default class SourceDeltaGenerate extends SfCommand<SgdResult> {
char: 'a',
summary: messages.getMessage('flags.api-version.summary'),
}),
// Deprecated flags start
ignore: Flags.file({
summary: messages.getMessage('flags.deprecated', ['ignore-file']),
exists: true,
}),
'ignore-destructive': Flags.file({
summary: messages.getMessage('flags.deprecated', [
'ignore-destructive-file',
]),
exists: true,
}),
include: Flags.file({
summary: messages.getMessage('flags.deprecated', ['include-file']),
exists: true,
}),
'include-destructive': Flags.file({
summary: messages.getMessage('flags.deprecated', [
'include-destructive-file',
]),
exists: true,
}),
output: Flags.directory({
summary: messages.getMessage('flags.deprecated', ['output-dir']),
exists: true,
}),
repo: Flags.directory({
summary: messages.getMessage('flags.deprecated', ['repo-dir']),
exists: true,
}),
source: Flags.directory({
summary: messages.getMessage('flags.deprecated', ['source-dir']),
exists: true,
}),
}

public async run(): Promise<SgdResult> {
Expand All @@ -135,8 +114,6 @@ export default class SourceDeltaGenerate extends SfCommand<SgdResult> {
to: flags['to'],
}

this.recoverOldParametersUsage(config, flags)

this.spinner.start(
messages.getMessage('info.CommandIsRunning'),
undefined,
Expand All @@ -158,28 +135,4 @@ export default class SourceDeltaGenerate extends SfCommand<SgdResult> {
this.spinner.stop(messages.getMessage('info.CommandHasRun'))
return output
}

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
private recoverOldParametersUsage(config: Config, flags: any) {
for (const [oldParameter, newParameter] of Object.entries({
ignore: 'ignore-file',
'ignore-destructive': 'ignore-destructive-file',
include: 'include-file',
'include-destructive': 'include-destructive-file',
output: 'output-dir',
repo: 'repo-dir',
source: 'source-dir',
})) {
if (oldParameter in flags) {
this.warn(
messages.getMessage('warning.oldParameters', [
oldParameter,
newParameter,
])
)
const configAttribut = camelCase(oldParameter) as never
config[configAttribut] = flags[oldParameter as never] as never
}
}
}
}

0 comments on commit d0d592d

Please sign in to comment.