Skip to content

Commit

Permalink
fix: args
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Nov 19, 2020
1 parent dee7eb1 commit 5ed3806
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 48 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.7",
"@typescript-eslint/eslint-plugin": "^4.8.0",
"@typescript-eslint/parser": "^4.8.0",
"@types/node": "^14.14.8",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"cross-env": "^7.0.2",
"eslint": "^7.13.0",
"husky": "^4.3.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/util/src/Node/Argv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {assert} from "../assert";
import {isDefined, isNumber} from "../is";
import {entriesReverse} from "../object";

const OPTION_REGEX = /^--([a-z0-9_-]+)=(.+)$/i;
const FLAG_ON_REGEX = /^-([a-z0-9]+)$/i;
Expand All @@ -23,6 +24,15 @@ export class Argv {
this.options = options;
}

public toObject(): Record<string, string | boolean> {
const entries: [string, boolean | string][] = [
...this.flags.entries(),
...this.options.entries(),
];

return entriesReverse(entries);
}

public getFlag(name: string, defaultValue = false): boolean {
return this.flags.get(name) || defaultValue;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/util/test/src/node/Argv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe("Cli", () => {
options: new Map(Object.entries({kv: "value", port: "123"})),
args: new Set(["argument1", "argument2"]),
});

expect(args.toObject()).toMatchSnapshot();
});

test("Options normalization should work", () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/util/test/src/node/__snapshots__/Argv.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Cli Parser should work 1`] = `
Object {
"f": true,
"kv": "value",
"not": false,
"port": "123",
}
`;
90 changes: 45 additions & 45 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1684,10 +1684,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1"
integrity sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==

"@types/node@^14.14.7":
version "14.14.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.7.tgz#8ea1e8f8eae2430cf440564b98c6dfce1ec5945d"
integrity sha512-Zw1vhUSQZYw+7u5dAwNbIA9TuTotpzY/OF7sJM9FqPOF3SPjKnxrjoTktXDZgUjybf4cWVBP7O8wvKdSaGHweg==
"@types/node@^14.14.8":
version "14.14.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
Expand Down Expand Up @@ -1721,74 +1721,74 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^4.8.0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.8.0.tgz#ad12cba28e426b24295291ad4c43b1cdc8b9dbb1"
integrity sha512-nm80Yy5D7Ot00bomzBYodnGmGhNdePHS3iaxJ3Th0wxRWEI/6KCgbmL8PR78fF7MtT1VDcYNtY5y+YYyGlRhBg==
"@typescript-eslint/eslint-plugin@^4.8.1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.8.1.tgz#b362abe0ee478a6c6d06c14552a6497f0b480769"
integrity sha512-d7LeQ7dbUrIv5YVFNzGgaW3IQKMmnmKFneRWagRlGYOSfLJVaRbj/FrBNOBC1a3tVO+TgNq1GbHvRtg1kwL0FQ==
dependencies:
"@typescript-eslint/experimental-utils" "4.8.0"
"@typescript-eslint/scope-manager" "4.8.0"
"@typescript-eslint/experimental-utils" "4.8.1"
"@typescript-eslint/scope-manager" "4.8.1"
debug "^4.1.1"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected].0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.8.0.tgz#ff035f917aec0698c156a6039166ecf9d7a24f57"
integrity sha512-1yOvI++HMdA9lpaAkXXQlVUwJjruNz7Z9K3lgpcU+JU/Szvsv42H6G6DECalAuz2Dd0KFU/MeUrPC0jXnuAvlA==
"@typescript-eslint/[email protected].1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.8.1.tgz#27275c20fa4336df99ebcf6195f7d7aa7aa9f22d"
integrity sha512-WigyLn144R3+lGATXW4nNcDJ9JlTkG8YdBWHkDlN0lC3gUGtDi7Pe3h5GPvFKMcRz8KbZpm9FJV9NTW8CpRHpg==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/scope-manager" "4.8.0"
"@typescript-eslint/types" "4.8.0"
"@typescript-eslint/typescript-estree" "4.8.0"
"@typescript-eslint/scope-manager" "4.8.1"
"@typescript-eslint/types" "4.8.1"
"@typescript-eslint/typescript-estree" "4.8.1"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/parser@^4.8.0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.8.0.tgz#ff98c0435a3797d17083a63389078b8aa49dc81e"
integrity sha512-15sp9BIoZalx4wRgkebfau8KizVe6w0eTjPMnuST9kbIeOaloDy1xKkg7eJfFvE/MdCtKlEWZFLoJB8C0SEOaw==
"@typescript-eslint/parser@^4.8.1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.8.1.tgz#4fe2fbdbb67485bafc4320b3ae91e34efe1219d1"
integrity sha512-QND8XSVetATHK9y2Ltc/XBl5Ro7Y62YuZKnPEwnNPB8E379fDsvzJ1dMJ46fg/VOmk0hXhatc+GXs5MaXuL5Uw==
dependencies:
"@typescript-eslint/scope-manager" "4.8.0"
"@typescript-eslint/types" "4.8.0"
"@typescript-eslint/typescript-estree" "4.8.0"
"@typescript-eslint/scope-manager" "4.8.1"
"@typescript-eslint/types" "4.8.1"
"@typescript-eslint/typescript-estree" "4.8.1"
debug "^4.1.1"

"@typescript-eslint/[email protected].0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.8.0.tgz#f960b6c5df1a5b230b8488e71c5c04e58dd494e0"
integrity sha512-eJ+SV6w5WcyFusQ/Ru4A/c7E65HMGzWWGPJAqSuM/1EKEE6wOw9LUQTqAvLa6v2oIcaDo9F+/EyOPZgoD/BcLA==
"@typescript-eslint/[email protected].1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.8.1.tgz#e343c475f8f1d15801b546cb17d7f309b768fdce"
integrity sha512-r0iUOc41KFFbZdPAdCS4K1mXivnSZqXS5D9oW+iykQsRlTbQRfuFRSW20xKDdYiaCoH+SkSLeIF484g3kWzwOQ==
dependencies:
"@typescript-eslint/types" "4.8.0"
"@typescript-eslint/visitor-keys" "4.8.0"
"@typescript-eslint/types" "4.8.1"
"@typescript-eslint/visitor-keys" "4.8.1"

"@typescript-eslint/[email protected].0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.8.0.tgz#87e73883637f662d9a638b0e9b01ed77edc44fb7"
integrity sha512-2/mGmXxr3sTxCvCT1mhR2b9rbfpMEBK41tiu0lMnMtZEbpphcUyrmgt2ogDFWNvsvyyeUxO1159eDrgFb7zV4Q==
"@typescript-eslint/[email protected].1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.8.1.tgz#23829c73c5fc6f4fcd5346a7780b274f72fee222"
integrity sha512-ave2a18x2Y25q5K05K/U3JQIe2Av4+TNi/2YuzyaXLAsDx6UZkz1boZ7nR/N6Wwae2PpudTZmHFXqu7faXfHmA==

"@typescript-eslint/[email protected].0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.0.tgz#b5160588495f18b739003b6078309b76fece0c55"
integrity sha512-jEdeERN8DIs7S8PlTdI7Sdy63Caxg2VtR21/RV7Z1Dtixiq/QEFSPrDXggMXKNOPPlrtMS+eCz7d7NV0HWLFVg==
"@typescript-eslint/[email protected].1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.1.tgz#7307e3f2c9e95df7daa8dc0a34b8c43b7ec0dd32"
integrity sha512-bJ6Fn/6tW2g7WIkCWh3QRlaSU7CdUUK52shx36/J7T5oTQzANvi6raoTsbwGM11+7eBbeem8hCCKbyvAc0X3sQ==
dependencies:
"@typescript-eslint/types" "4.8.0"
"@typescript-eslint/visitor-keys" "4.8.0"
"@typescript-eslint/types" "4.8.1"
"@typescript-eslint/visitor-keys" "4.8.1"
debug "^4.1.1"
globby "^11.0.1"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected].0":
version "4.8.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.0.tgz#7786b92bbaf25c6aa9fb860eb8dbb1f7d3b7d0ad"
integrity sha512-JluNZLvnkRUr0h3L6MnQVLuy2rw9DpD0OyMC21FVbgcezr0LQkbBjDp9kyKZhuZrLrtq4mwPiIkpfRb8IRqneA==
"@typescript-eslint/[email protected].1":
version "4.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.1.tgz#794f68ee292d1b2e3aa9690ebedfcb3a8c90e3c3"
integrity sha512-3nrwXFdEYALQh/zW8rFwP4QltqsanCDz4CwWMPiIZmwlk9GlvBeueEIbq05SEq4ganqM0g9nh02xXgv5XI3PeQ==
dependencies:
"@typescript-eslint/types" "4.8.0"
"@typescript-eslint/types" "4.8.1"
eslint-visitor-keys "^2.0.0"

"@zkochan/cmd-shim@^3.1.0":
Expand Down

0 comments on commit 5ed3806

Please sign in to comment.