Skip to content

Commit

Permalink
feat: implement compliant cli parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Oct 8, 2024
1 parent 51d3677 commit e283182
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 60 deletions.
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,32 @@ Generate incremental package manifest and source content

```
USAGE
$ sf sgd source delta -f <value> [--json] [--flags-dir <value>] [-a <value>] [-d] [-i <value>] [-D <value>] [-W] [-n
<value>] [-N <value>] [-o <value>] [-r <value>] [-s <value>] [-t <value>]
$ sf sgd source delta -f <value> [--json] [--flags-dir <value>] [-a <value>] [-d] [--ignore <value>] [-i <value>]
[--ignore-destructive <value>] [-D <value>] [-W] [--include <value>] [-n <value>] [--include-destructive <value>]
[-N <value>] [--output <value>] [-o <value>] [--repo <value>] [-r <value>] [--source <value>] [-s <value>] [-t
<value>]
FLAGS
-D, --ignore-destructive=<value> file listing paths to explicitly ignore for any destructive actions
-N, --include-destructive=<value> file listing paths to explicitly include for any destructive actions
-W, --ignore-whitespace ignore git diff whitespace (space, tab, eol) changes
-a, --api-version=<value> salesforce metadata API version, default to sfdx-project.json "sourceApiVersion"
attribute or latest version
-d, --generate-delta generate delta files in [--output] folder
-f, --from=<value> (required) commit sha from where the diff is done
-i, --ignore=<value> file listing paths to explicitly ignore for any diff actions
-n, --include=<value> file listing paths to explicitly include for any diff actions
-o, --output=<value> [default: ./output] source package specific output
-r, --repo=<value> [default: ./] git repository location
-s, --source=<value> [default: ./] source folder focus location related to --repo
-t, --to=<value> [default: HEAD] commit sha to where the diff is done
-D, --ignore-destructive-file=<value> file listing paths to explicitly ignore for any destructive actions
-N, --include-destructive-file=<value> file listing paths to explicitly include for any destructive actions
-W, --ignore-whitespace ignore git diff whitespace (space, tab, eol) changes
-a, --api-version=<value> salesforce metadata API version, default to sfdx-project.json
"sourceApiVersion" attribute or latest version
-d, --generate-delta generate delta files in [--output] folder
-f, --from=<value> (required) commit sha from where the diff is done
-i, --ignore-file=<value> file listing paths to explicitly ignore for any diff actions
-n, --include-file=<value> file listing paths to explicitly include for any diff actions
-o, --output-dir=<value> [default: ./output] source package specific output
-r, --repo-dir=<value> [default: ./] git repository location
-s, --source-dir=<value> [default: ./] source folder focus location related to --repo
-t, --to=<value> [default: HEAD] commit sha to where the diff is done
--ignore=<value> /!\ deprecated, use '--ignore-file' instead.
--ignore-destructive=<value> /!\ deprecated, use '--ignore-destructive-file' instead.
--include=<value> /!\ deprecated, use '--include-file' instead.
--include-destructive=<value> /!\ deprecated, use '--include-destructive-file' instead.
--output=<value> /!\ deprecated, use '--output-dir' instead.
--repo=<value> /!\ deprecated, use '--repo-dir' instead.
--source=<value> /!\ deprecated, use '--source-dir' instead.
GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
Expand Down
3 changes: 1 addition & 2 deletions __tests__/functional/delta.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ describe('sgd source delta NUTS', () => {
)
expect(packageLineCount).to.equal(232)
expect(destructiveChangesLineCount).to.equal(137)
expect(result).to.include('"error": null')
expect(result).to.include('"success": true')
expect(result).to.include('"status": 0')
})
})

Expand Down
7 changes: 7 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@
"generate-delta",
"ignore",
"ignore-destructive",
"ignore-destructive-file",
"ignore-file",
"ignore-whitespace",
"include",
"include-destructive",
"include-destructive-file",
"include-file",
"json",
"output",
"output-dir",
"repo",
"repo-dir",
"source",
"source-dir",
"to"
],
"plugin": "sfdx-git-delta"
Expand Down
8 changes: 8 additions & 0 deletions messages/delta.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ 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 @@ -80,6 +84,10 @@ API version not found or not supported, using '%s' instead

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

Generating incremental package
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
]
},
"lint:deprecation-policy": {
"command": "./bin/dev.js snapshot:compare",
"command": "./bin/dev.js snapshot compare",
"files": [
"lib/commands/**/*.ts"
],
Expand All @@ -216,7 +216,7 @@
]
},
"lint:json-schema": {
"command": "./bin/dev.js schema:compare",
"command": "./bin/dev.js schema compare",
"files": [
"lib/commands/**/*.ts",
"schemas"
Expand Down
21 changes: 3 additions & 18 deletions schemas/sgd-source-delta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,14 @@
"type": "object",
"properties": {
"error": {
"type": [
"string",
"null"
]
},
"output": {
"type": "string"
},
"success": {
"type": "boolean"
},
"warnings": {
"type": "array",
"items": {
"type": "string"
}
"output-dir": {
"type": "string"
}
},
"required": [
"error",
"output",
"success",
"warnings"
"output-dir"
],
"additionalProperties": false
}
Expand Down
92 changes: 73 additions & 19 deletions src/commands/sgd/source/delta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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 All @@ -34,11 +36,21 @@ export default class SourceDeltaGenerate extends SfCommand<SgdResult> {
summary: messages.getMessage('flags.generate-delta.summary'),
}),
ignore: Flags.file({
summary: messages.getMessage('flags.deprecated', ['ignore-file']),
exists: true,
}),
'ignore-file': Flags.file({
char: 'i',
summary: messages.getMessage('flags.ignore.summary'),
exists: true,
}),
'ignore-destructive': Flags.file({
summary: messages.getMessage('flags.deprecated', [
'ignore-destructive-file',
]),
exists: true,
}),
'ignore-destructive-file': Flags.file({
char: 'D',
summary: messages.getMessage('flags.ignore-destructive.summary'),
exists: true,
Expand All @@ -48,28 +60,50 @@ export default class SourceDeltaGenerate extends SfCommand<SgdResult> {
summary: messages.getMessage('flags.ignore-whitespace.summary'),
}),
include: Flags.file({
summary: messages.getMessage('flags.deprecated', ['include-file']),
exists: true,
}),
'include-file': Flags.file({
char: 'n',
summary: messages.getMessage('flags.include.summary'),
exists: true,
}),
'include-destructive': Flags.file({
summary: messages.getMessage('flags.deprecated', [
'include-destructive-file',
]),
exists: true,
}),
'include-destructive-file': Flags.file({
char: 'N',
summary: messages.getMessage('flags.include-destructive.summary'),
exists: true,
}),
output: Flags.directory({
summary: messages.getMessage('flags.deprecated', ['output-dir']),
exists: true,
}),
'output-dir': Flags.directory({
char: 'o',
summary: messages.getMessage('flags.output.summary'),
default: OUTPUT_DEFAULT_VALUE,
exists: true,
}),
repo: Flags.directory({
summary: messages.getMessage('flags.deprecated', ['repo-dir']),
exists: true,
}),
'repo-dir': Flags.directory({
char: 'r',
summary: messages.getMessage('flags.repo.summary'),
default: REPO_DEFAULT_VALUE,
exists: true,
}),
source: Flags.directory({
summary: messages.getMessage('flags.deprecated', ['source-dir']),
exists: true,
}),
'source-dir': Flags.directory({
char: 's',
summary: messages.getMessage('flags.source.summary'),
default: SOURCE_DEFAULT_VALUE,
Expand All @@ -84,46 +118,66 @@ export default class SourceDeltaGenerate extends SfCommand<SgdResult> {

public async run(): Promise<SgdResult> {
const { flags } = await this.parse(SourceDeltaGenerate)
const output: SgdResult = {
error: null,
output: flags['output'],
success: true,
warnings: [],
}

const config: Config = {
apiVersion: flags['api-version'],
from: flags['from'],
generateDelta: flags['generate-delta'],
ignore: flags['ignore'],
ignoreDestructive: flags['ignore-destructive'],
ignore: flags['ignore-file'],
ignoreDestructive: flags['ignore-destructive-file'],
ignoreWhitespace: flags['ignore-whitespace'],
include: flags['include'],
includeDestructive: flags['include-destructive'],
output: flags['output'],
repo: flags['repo'],
source: flags['source'],
include: flags['include-file'],
includeDestructive: flags['include-destructive-file'],
output: flags['output-dir'],
repo: flags['repo-dir'],
source: flags['source-dir'],
to: flags['to'],
}

this.recoverOldParametersUsage(config, flags)

this.spinner.start(
messages.getMessage('info.CommandIsRunning'),
undefined,
{ stdout: true }
)
const output: SgdResult = {
'output-dir': config.output,
}
try {
const jobResult = await sgd(config)
if (jobResult.warnings?.length > 0) {
output.warnings = jobResult.warnings.map(
(warning: Error) => warning.message
)
}
jobResult.warnings?.forEach(this.warn)
} catch (err) {
if (err instanceof Error) {
output.error = err.message
}
output.success = false
process.exitCode = 1
}
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
}
}
}
}
6 changes: 2 additions & 4 deletions src/types/sgdResult.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export type SgdResult = {
error: string | null
output: string
success: boolean
warnings: string[]
error?: string
'output-dir': string
}

0 comments on commit e283182

Please sign in to comment.