Skip to content

Commit

Permalink
feat: add array style flag for backward compatibility (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
peternhale committed Dec 7, 2022
1 parent b5bb815 commit b1844a4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
4 changes: 4 additions & 0 deletions messages/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ Set varargs with this format: key=value or key="value with spaces".
# error.DuplicateArgument

Found duplicate argument %s.

# warning.arrayInputFormat

The input format for array arguments has changed. Use this format: --array-flag value1 --array-flag value2 --array-flag value3
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"/messages"
],
"dependencies": {
"@oclif/core": "^1.20.4",
"@oclif/core": "^1.21.0",
"@salesforce/core": "^3.32.6",
"@salesforce/kit": "^1.7.1",
"@salesforce/ts-types": "^1.7.1",
Expand Down Expand Up @@ -71,4 +71,4 @@
"publishConfig": {
"access": "public"
}
}
}
21 changes: 20 additions & 1 deletion src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { Flags } from '@oclif/core';
import { Messages } from '@salesforce/core';
import { Lifecycle, Messages } from '@salesforce/core';
import { OptionFlagProps } from '@oclif/core/lib/interfaces';
import { orgApiVersionFlag } from './flags/orgApiVersion';
import { optionalOrgFlag, requiredHubFlag, requiredOrgFlag } from './flags/orgFlags';

Expand Down Expand Up @@ -74,3 +75,21 @@ export const requiredHubFlagWithDeprecations = requiredHubFlag({
aliases: ['targetdevhubusername'],
deprecateAliases: true,
});

/**
* @deprecated
*/
export const arrayWithDeprecation = (options: Partial<Omit<OptionFlagProps, 'multiple' | 'parse'>>) =>
Flags.string({
// populate passed options
...options,
// overlay those options we own
multiple: true,
parse: async (input: string) => {
const inputParts = input.split(',').map((i) => i.trim());
if (inputParts.length > 1) {
await Lifecycle.getInstance().emitWarning(messages.getMessage('warning.arrayInputFormat'));
}
return inputParts;
},
});
34 changes: 34 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,40 @@
widest-line "^3.1.0"
wrap-ansi "^7.0.0"

"@oclif/core@^1.21.0":
version "1.21.0"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.21.0.tgz#d91b2f40a4f446279ab6335c619fc1716fc23ab6"
integrity sha512-B/AKYfHcNRAbb6Xz2kj0FlH9gWEi8aFS4iEr7EzguP3E2DpDk4wcf7eOMOfJYEmhuVd9sOpVWSnI2yP+FL/3Sg==
dependencies:
"@oclif/linewrap" "^1.0.0"
"@oclif/screen" "^3.0.3"
ansi-escapes "^4.3.2"
ansi-styles "^4.3.0"
cardinal "^2.1.1"
chalk "^4.1.2"
clean-stack "^3.0.1"
cli-progress "^3.10.0"
debug "^4.3.4"
ejs "^3.1.6"
fs-extra "^9.1.0"
get-package-type "^0.1.0"
globby "^11.1.0"
hyperlinker "^1.0.0"
indent-string "^4.0.0"
is-wsl "^2.2.0"
js-yaml "^3.14.1"
natural-orderby "^2.0.3"
object-treeify "^1.1.33"
password-prompt "^1.1.2"
semver "^7.3.7"
string-width "^4.2.3"
strip-ansi "^6.0.1"
supports-color "^8.1.1"
supports-hyperlinks "^2.2.0"
tslib "^2.4.1"
widest-line "^3.1.0"
wrap-ansi "^7.0.0"

"@oclif/dev-cli@^1":
version "1.26.0"
resolved "https://registry.npmjs.org/@oclif/dev-cli/-/dev-cli-1.26.0.tgz#e3ec294b362c010ffc8948003d3770955c7951fd"
Expand Down

0 comments on commit b1844a4

Please sign in to comment.