Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

fix: sfdx string flags parse #193

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"skipFiles": ["<node_internals>/**"]
},
{
"name": "Run All Tests",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": ["--inspect", "--no-timeouts", "--colors", "test/**/*.test.ts"],
"env": {
"NODE_ENV": "development",
"SFDX_ENV": "development"
},
"sourceMaps": true,
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "Compile"
},
{
"type": "node",
"request": "launch",
"name": "Run Current Test",
"sourceMaps": true,
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": ["--inspect", "--no-timeouts", "--colors", "${file}"],
"env": {
"NODE_ENV": "development",
"SFDX_ENV": "development",
"OCLIF_TS_NODE": "0"
},
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "Compile"
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@oclif/core": "^1.20.4",
"@oclif/test": "^2.2.10",
"@salesforce/core": "^3.31.17",
"@salesforce/core": "^3.32.1",
"@salesforce/kit": "^1.8.0",
"@salesforce/ts-types": "^1.7.1",
"chalk": "^2.4.2"
Expand Down Expand Up @@ -71,4 +71,4 @@
"publishConfig": {
"access": "public"
}
}
}
8 changes: 4 additions & 4 deletions src/sfdxFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Omit,
Optional,
} from '@salesforce/ts-types';
import { CustomOptionFlag } from '@oclif/core/lib/interfaces/parser';
import { CustomOptionFlag, FlagParser } from '@oclif/core/lib/interfaces/parser';
import { Deprecation } from './ux';

Messages.importMessagesDirectory(__dirname);
Expand Down Expand Up @@ -108,7 +108,7 @@ function merge<T>(
function option<T>(
kind: flags.Kind,
options: flags.Option<T>,
parse: (val: string, ctx: unknown) => Promise<T>
parse: ((val: string, ctx: unknown) => Promise<T>) | FlagParser<T, string>
): flags.Discriminated<flags.Option<T>> {
const flag = OclifFlags.option({ ...options, parse });
return merge<T>(kind, flag, options);
Expand Down Expand Up @@ -221,7 +221,7 @@ function buildOption<T>(
}

function buildString(options: flags.String): flags.Discriminated<flags.String> {
return option('string', options, (val: string) => Promise.resolve(val));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version was always setting parse to a no-op

return option('string', options, options.parse ?? ((val: string) => Promise.resolve(val)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parse function is on the options object, so bring that out

}

function buildVersion(options?: flags.BaseBoolean<boolean>): flags.Discriminated<flags.Boolean<void>> {
Expand Down Expand Up @@ -281,7 +281,7 @@ function buildMappedArray<T>(kind: flags.Kind, options: flags.MappedArray<T>): f
function buildStringArray(kind: flags.Kind, options: flags.Array<string>): flags.Discriminated<flags.Option<string[]>> {
const { options: values, ...rest } = options;
const allowed = new Set(values);
return option(kind, rest, (val): Promise<string[]> => {
return option(kind, rest, (val: string): Promise<string[]> => {
const vals = convertArrayFlagToArray(val, options.delimiter);
validateArrayValues(kind, val, vals, options.validate);
validateArrayOptions(kind, val, vals, allowed);
Expand Down
12 changes: 12 additions & 0 deletions test/unit/sfdxFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,16 @@ describe('SfdxFlags', () => {
});
});
});

describe('parse', () => {
it('parse on string flag', async () => {
const flag = flags.string({
description: 'test',
parse: (input: string) => Promise.resolve(input.toUpperCase()),
});
if (!hasFunction(flag, 'parse')) throw new MissingPropertyError('parse', 'array');

expect(await flag.parse('foo', undefined, undefined)).to.equal('FOO');
});
});
});
19 changes: 7 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,13 @@
mv "~2"
safe-json-stringify "~1"

"@salesforce/core@^3.31.17":
version "3.31.17"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.31.17.tgz#83ab3c9c4730223943ceef4798aaa901fec7981e"
integrity sha512-rn3AYyePp3m1+IH+KVi+DWwMPcAPDYFiUxyJLh+Jr2hNj9i79eQBcUix6wunK3HaVz0N6Tm5FGIpjqfEVsU0cA==
"@salesforce/core@^3.32.1":
version "3.32.1"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.32.1.tgz#1a338a1985c58c1be819f99c6b33b24b32817cbe"
integrity sha512-hVcweKGy1CS3t0duS+0jxGVou5ZoQMXRZPQmcz1FyW31Oef5U07rhs3wTrwJqhCPHL817R/gm5V9wSRNcYdDtA==
dependencies:
"@salesforce/bunyan" "^2.0.0"
"@salesforce/kit" "^1.7.0"
"@salesforce/kit" "^1.8.0"
"@salesforce/schemas" "^1.1.0"
"@salesforce/ts-types" "^1.5.21"
"@types/graceful-fs" "^4.1.5"
Expand Down Expand Up @@ -789,7 +789,7 @@
typedoc-plugin-missing-exports "0.23.0"
typescript "^4.1.3"

"@salesforce/kit@^1.7.0", "@salesforce/kit@^1.8.0":
"@salesforce/kit@^1.8.0":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.8.0.tgz#d5b8d83d5b0b866cb76840dc7a18e115589d86a0"
integrity sha512-Pr9CWAIzVYKZRWvM76lyhEtF3CPmVdIfgbqRD7KT/YZdbLstX3KHYBxCyx3TyWZr5qROv96n+jRIBiIFI9LGGw==
Expand Down Expand Up @@ -981,16 +981,11 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/semver@^7.3.12":
"@types/semver@^7.3.12", "@types/semver@^7.3.9":
version "7.3.13"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91"
integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==

"@types/semver@^7.3.9":
version "7.3.12"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.12.tgz#920447fdd78d76b19de0438b7f60df3c4a80bf1c"
integrity sha512-WwA1MW0++RfXmCr12xeYOOC5baSC9mSb0ZqCquFzKhcoF4TvHu5MKOuXsncgZcpVFhB1pXd5hZmM0ryAoCp12A==

"@types/sinon@*":
version "10.0.13"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-10.0.13.tgz#60a7a87a70d9372d0b7b38cc03e825f46981fb83"
Expand Down