track-cli 3.0.0-rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +3 -0
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/_dnt.shims.d.ts +19 -0
- package/esm/_dnt.shims.js +78 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
- package/esm/package.json +3 -0
- package/esm/src/action/add.d.ts +1 -0
- package/esm/src/action/add.js +57 -0
- package/esm/src/action/clone.d.ts +6 -0
- package/esm/src/action/clone.js +108 -0
- package/esm/src/action/lang.d.ts +1 -0
- package/esm/src/action/lang.js +40 -0
- package/esm/src/action/pull.d.ts +1 -0
- package/esm/src/action/pull.js +22 -0
- package/esm/src/action/remove.d.ts +4 -0
- package/esm/src/action/remove.js +67 -0
- package/esm/src/action/reset.d.ts +1 -0
- package/esm/src/action/reset.js +21 -0
- package/esm/src/action/run.d.ts +4 -0
- package/esm/src/action/run.js +163 -0
- package/esm/src/action/status.d.ts +1 -0
- package/esm/src/action/status.js +5 -0
- package/esm/src/main.d.ts +2 -0
- package/esm/src/main.js +96 -0
- package/esm/src/meta.d.ts +3 -0
- package/esm/src/meta.js +51 -0
- package/esm/src/orca/client.d.ts +20 -0
- package/esm/src/orca/client.js +152 -0
- package/esm/src/orca/types.d.ts +54 -0
- package/esm/src/orca/types.js +12 -0
- package/esm/src/shared/config.d.ts +24 -0
- package/esm/src/shared/config.js +24 -0
- package/esm/src/shared/errors.d.ts +82 -0
- package/esm/src/shared/errors.js +228 -0
- package/esm/src/shared/file.d.ts +30 -0
- package/esm/src/shared/file.js +110 -0
- package/esm/src/shared/mod.d.ts +40 -0
- package/esm/src/shared/mod.js +383 -0
- package/esm/src/shared/types.d.ts +12 -0
- package/esm/src/shared/types.js +1 -0
- package/esm/src/track/client.d.ts +60 -0
- package/esm/src/track/client.js +268 -0
- package/esm/src/track/types.d.ts +210 -0
- package/esm/src/track/types.js +40 -0
- package/package.json +35 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { distance } from "../_utils/distance.js";
|
|
2
|
+
/** Convert param case string to camel case. */
|
|
3
|
+
export function paramCaseToCamelCase(str) {
|
|
4
|
+
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
5
|
+
}
|
|
6
|
+
/** Convert underscore case string to camel case. */
|
|
7
|
+
export function underscoreToCamelCase(str) {
|
|
8
|
+
return str
|
|
9
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Find option by flag, name or alias.
|
|
15
|
+
*
|
|
16
|
+
* @param flags Source options array.
|
|
17
|
+
* @param name Name of the option.
|
|
18
|
+
*/
|
|
19
|
+
export function getOption(flags, name) {
|
|
20
|
+
while (name[0] === "-") {
|
|
21
|
+
name = name.slice(1);
|
|
22
|
+
}
|
|
23
|
+
for (const flag of flags) {
|
|
24
|
+
if (isOption(flag, name)) {
|
|
25
|
+
return flag;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
export function didYouMeanOption(option, options) {
|
|
31
|
+
const optionNames = options
|
|
32
|
+
.map((option) => [option.name, ...(option.aliases ?? [])])
|
|
33
|
+
.flat()
|
|
34
|
+
.map((option) => getFlag(option));
|
|
35
|
+
return didYouMean(" Did you mean option", getFlag(option), optionNames);
|
|
36
|
+
}
|
|
37
|
+
export function didYouMeanType(type, types) {
|
|
38
|
+
return didYouMean(" Did you mean type", type, types);
|
|
39
|
+
}
|
|
40
|
+
export function didYouMean(message, type, types) {
|
|
41
|
+
const match = closest(type, types);
|
|
42
|
+
return match ? `${message} "${match}"?` : "";
|
|
43
|
+
}
|
|
44
|
+
export function getFlag(name) {
|
|
45
|
+
if (name.startsWith("-")) {
|
|
46
|
+
return name;
|
|
47
|
+
}
|
|
48
|
+
if (name.length > 1) {
|
|
49
|
+
return `--${name}`;
|
|
50
|
+
}
|
|
51
|
+
return `-${name}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if option has name or alias.
|
|
55
|
+
*
|
|
56
|
+
* @param option The option to check.
|
|
57
|
+
* @param name The option name or alias.
|
|
58
|
+
*/
|
|
59
|
+
function isOption(option, name) {
|
|
60
|
+
return option.name === name ||
|
|
61
|
+
(option.aliases && option.aliases.indexOf(name) !== -1);
|
|
62
|
+
}
|
|
63
|
+
export function matchWildCardOptions(name, flags) {
|
|
64
|
+
for (const option of flags) {
|
|
65
|
+
if (option.name.indexOf("*") === -1) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
let matched = matchWildCardOption(name, option);
|
|
69
|
+
if (matched) {
|
|
70
|
+
matched = { ...matched, name };
|
|
71
|
+
flags.push(matched);
|
|
72
|
+
return matched;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function matchWildCardOption(name, option) {
|
|
77
|
+
const parts = option.name.split(".");
|
|
78
|
+
const parts2 = name.split(".");
|
|
79
|
+
if (parts.length !== parts2.length) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const count = Math.max(parts.length, parts2.length);
|
|
83
|
+
for (let i = 0; i < count; i++) {
|
|
84
|
+
if (parts[i] !== parts2[i] && parts[i] !== "*") {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return option;
|
|
89
|
+
}
|
|
90
|
+
function closest(str, arr) {
|
|
91
|
+
let minDistance = Infinity;
|
|
92
|
+
let minIndex = 0;
|
|
93
|
+
for (let i = 0; i < arr.length; i++) {
|
|
94
|
+
const dist = distance(str, arr[i]);
|
|
95
|
+
if (dist < minDistance) {
|
|
96
|
+
minDistance = dist;
|
|
97
|
+
minIndex = i;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return arr[minIndex];
|
|
101
|
+
}
|
|
102
|
+
export function getDefaultValue(option) {
|
|
103
|
+
return typeof option.default === "function"
|
|
104
|
+
? option.default()
|
|
105
|
+
: option.default;
|
|
106
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ParseFlagsContext, ParseFlagsOptions } from "./types.js";
|
|
2
|
+
import type { FlagOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Flags post validation. Validations that are not already done by the parser.
|
|
5
|
+
*
|
|
6
|
+
* @param ctx Parse context.
|
|
7
|
+
* @param opts Parse options.
|
|
8
|
+
* @param options Option name mappings: propertyName -> option
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateFlags<T extends FlagOptions = FlagOptions>(ctx: ParseFlagsContext<Record<string, unknown>>, opts: ParseFlagsOptions<T>, options?: Map<string, FlagOptions>): void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { getDefaultValue, getOption, paramCaseToCamelCase } from "./_utils.js";
|
|
2
|
+
import { ConflictingOptionError, DependingOptionError, MissingOptionValueError, MissingRequiredOptionError, OptionNotCombinableError, UnknownOptionError, } from "./_errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Flags post validation. Validations that are not already done by the parser.
|
|
5
|
+
*
|
|
6
|
+
* @param ctx Parse context.
|
|
7
|
+
* @param opts Parse options.
|
|
8
|
+
* @param options Option name mappings: propertyName -> option
|
|
9
|
+
*/
|
|
10
|
+
export function validateFlags(ctx, opts, options = new Map()) {
|
|
11
|
+
if (!opts.flags) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const defaultValues = setDefaultValues(ctx, opts);
|
|
15
|
+
const optionNames = Object.keys(ctx.flags);
|
|
16
|
+
if (!optionNames.length && opts.allowEmpty) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (ctx.standalone) {
|
|
20
|
+
validateStandaloneOption(ctx, options, optionNames, defaultValues);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const [name, option] of options) {
|
|
24
|
+
validateUnknownOption(option, opts);
|
|
25
|
+
validateConflictingOptions(ctx, option);
|
|
26
|
+
validateDependingOptions(ctx, option, defaultValues);
|
|
27
|
+
validateRequiredValues(ctx, option, name);
|
|
28
|
+
}
|
|
29
|
+
validateRequiredOptions(ctx, options, opts);
|
|
30
|
+
}
|
|
31
|
+
function validateUnknownOption(option, opts) {
|
|
32
|
+
if (!getOption(opts.flags ?? [], option.name)) {
|
|
33
|
+
throw new UnknownOptionError(option.name, opts.flags ?? []);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Adds all default values to ctx.flags and returns a boolean object map with
|
|
38
|
+
* only the default option names `{ [OptionName: string]: boolean }`.
|
|
39
|
+
*/
|
|
40
|
+
function setDefaultValues(ctx, opts) {
|
|
41
|
+
const defaultValues = {};
|
|
42
|
+
if (!opts.flags?.length) {
|
|
43
|
+
return defaultValues;
|
|
44
|
+
}
|
|
45
|
+
// Set default values
|
|
46
|
+
for (const option of opts.flags) {
|
|
47
|
+
let name;
|
|
48
|
+
let defaultValue = undefined;
|
|
49
|
+
// if --no-[flag] is present set --[flag] default value to true
|
|
50
|
+
if (option.name.startsWith("no-")) {
|
|
51
|
+
const propName = option.name.replace(/^no-/, "");
|
|
52
|
+
if (typeof ctx.flags[propName] !== "undefined") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const positiveOption = getOption(opts.flags, propName);
|
|
56
|
+
if (positiveOption) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
name = paramCaseToCamelCase(propName);
|
|
60
|
+
defaultValue = true;
|
|
61
|
+
}
|
|
62
|
+
if (!name) {
|
|
63
|
+
name = paramCaseToCamelCase(option.name);
|
|
64
|
+
}
|
|
65
|
+
const hasDefaultValue = (!opts.ignoreDefaults ||
|
|
66
|
+
typeof opts.ignoreDefaults[name] === "undefined") &&
|
|
67
|
+
typeof ctx.flags[name] === "undefined" && (typeof option.default !== "undefined" ||
|
|
68
|
+
typeof defaultValue !== "undefined");
|
|
69
|
+
if (hasDefaultValue) {
|
|
70
|
+
ctx.flags[name] = getDefaultValue(option) ?? defaultValue;
|
|
71
|
+
defaultValues[option.name] = true;
|
|
72
|
+
if (typeof option.value === "function") {
|
|
73
|
+
ctx.flags[name] = option.value(ctx.flags[name]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return defaultValues;
|
|
78
|
+
}
|
|
79
|
+
function validateStandaloneOption(ctx, options, optionNames, defaultValues) {
|
|
80
|
+
if (!ctx.standalone || optionNames.length === 1) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Don't throw an error if all values are coming from the default option.
|
|
84
|
+
for (const [_, opt] of options) {
|
|
85
|
+
if (!defaultValues[opt.name] && opt !== ctx.standalone) {
|
|
86
|
+
throw new OptionNotCombinableError(ctx.standalone.name);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function validateConflictingOptions(ctx, option) {
|
|
91
|
+
if (!option.conflicts?.length) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (const flag of option.conflicts) {
|
|
95
|
+
if (isset(flag, ctx.flags)) {
|
|
96
|
+
throw new ConflictingOptionError(option.name, flag);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function validateDependingOptions(ctx, option, defaultValues) {
|
|
101
|
+
if (!option.depends) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
for (const flag of option.depends) {
|
|
105
|
+
// Don't throw an error if the value is coming from the default option.
|
|
106
|
+
if (!isset(flag, ctx.flags) && !defaultValues[option.name]) {
|
|
107
|
+
throw new DependingOptionError(option.name, flag);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function validateRequiredValues(ctx, option, name) {
|
|
112
|
+
if (!option.args) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const isArray = option.args.length > 1;
|
|
116
|
+
for (let i = 0; i < option.args.length; i++) {
|
|
117
|
+
const arg = option.args[i];
|
|
118
|
+
if (!arg.requiredValue) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const hasValue = isArray
|
|
122
|
+
? typeof ctx.flags[name][i] !== "undefined"
|
|
123
|
+
: typeof ctx.flags[name] !== "undefined";
|
|
124
|
+
if (!hasValue) {
|
|
125
|
+
throw new MissingOptionValueError(option.name);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function validateRequiredOptions(ctx, options, opts) {
|
|
130
|
+
if (!opts.flags?.length) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const optionsValues = [...options.values()];
|
|
134
|
+
for (const option of opts.flags) {
|
|
135
|
+
if (!option.required || paramCaseToCamelCase(option.name) in ctx.flags) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const conflicts = option.conflicts ?? [];
|
|
139
|
+
const hasConflict = conflicts.find((flag) => !!ctx.flags[flag]);
|
|
140
|
+
const hasConflicts = hasConflict ||
|
|
141
|
+
optionsValues.find((opt) => opt.conflicts?.find((flag) => flag === option.name));
|
|
142
|
+
if (hasConflicts) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
throw new MissingRequiredOptionError(option.name);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Check if value exists for flag.
|
|
150
|
+
* @param flagName Flag name.
|
|
151
|
+
* @param flags Parsed values.
|
|
152
|
+
*/
|
|
153
|
+
function isset(flagName, flags) {
|
|
154
|
+
const name = paramCaseToCamelCase(flagName);
|
|
155
|
+
// return typeof values[ name ] !== 'undefined' && values[ name ] !== false;
|
|
156
|
+
return typeof flags[name] !== "undefined";
|
|
157
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ArgumentOptions, ArgumentValue, DefaultValue, FlagOptions, ParseFlagsContext, ParseFlagsOptions, TypeHandler, ValueHandler } from "./types.js";
|
|
2
|
+
/** @deprecated Use `ParseFlagsOptions` instead. */
|
|
3
|
+
export type IParseOptions<TFlagOptions extends FlagOptions = FlagOptions> = ParseFlagsOptions<TFlagOptions>;
|
|
4
|
+
/** @deprecated Use `FlagOptions` instead. */
|
|
5
|
+
export type IFlagOptions = FlagOptions;
|
|
6
|
+
/** @deprecated Use `ArgumentOptions` instead. */
|
|
7
|
+
export type IFlagArgument = ArgumentOptions;
|
|
8
|
+
/** @deprecated Use `DefaultValue` instead. */
|
|
9
|
+
export type IDefaultValue<TValue = unknown> = DefaultValue<TValue>;
|
|
10
|
+
/** @deprecated Use `ValueHandler` instead. */
|
|
11
|
+
export type IFlagValueHandler<TValue = any, TReturn = TValue> = ValueHandler<TValue, TReturn>;
|
|
12
|
+
/** @deprecated Use `ParseFlagsContext` instead. */
|
|
13
|
+
export type IFlagsResult<TFlags extends Record<string, any> = Record<string, any>, TStandaloneOption extends FlagOptions = FlagOptions> = ParseFlagsContext<TFlags, TStandaloneOption>;
|
|
14
|
+
/** @deprecated Use `ArgumentValue` instead. */
|
|
15
|
+
export type ITypeInfo = ArgumentValue;
|
|
16
|
+
/** @deprecated Use `TypeHandler` instead. */
|
|
17
|
+
export type ITypeHandler<TReturn = unknown> = TypeHandler<TReturn>;
|
|
18
|
+
/** @deprecated Use `ArgumentType` instead. */
|
|
19
|
+
export declare enum OptionType {
|
|
20
|
+
STRING = "string",
|
|
21
|
+
NUMBER = "number",
|
|
22
|
+
INTEGER = "integer",
|
|
23
|
+
BOOLEAN = "boolean"
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// deno-lint-ignore-file no-explicit-any
|
|
2
|
+
/** @deprecated Use `ArgumentType` instead. */
|
|
3
|
+
export var OptionType;
|
|
4
|
+
(function (OptionType) {
|
|
5
|
+
OptionType["STRING"] = "string";
|
|
6
|
+
OptionType["NUMBER"] = "number";
|
|
7
|
+
OptionType["INTEGER"] = "integer";
|
|
8
|
+
OptionType["BOOLEAN"] = "boolean";
|
|
9
|
+
})(OptionType || (OptionType = {}));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { FlagOptions, ParseFlagsContext, ParseFlagsOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parse command line arguments.
|
|
4
|
+
* @param argsOrCtx Command line arguments e.g: `Deno.args` or parse context.
|
|
5
|
+
* @param opts Parse options.
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* // examples/flags/flags.ts -x 3 -y.z -n5 -abc --beep=boop foo bar baz --deno.land --deno.com -- --cliffy
|
|
9
|
+
* parseFlags(Deno.args);
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Output:
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* {
|
|
16
|
+
* flags: {
|
|
17
|
+
* x: "3",
|
|
18
|
+
* y: { z: true },
|
|
19
|
+
* n: "5",
|
|
20
|
+
* a: true,
|
|
21
|
+
* b: true,
|
|
22
|
+
* c: true,
|
|
23
|
+
* beep: "boop",
|
|
24
|
+
* deno: { land: true, com: true }
|
|
25
|
+
* },
|
|
26
|
+
* literal: [ "--cliffy" ],
|
|
27
|
+
* unknown: [ "foo", "bar", "baz" ],
|
|
28
|
+
* stopEarly: false,
|
|
29
|
+
* stopOnUnknown: false
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseFlags<TFlags extends Record<string, unknown>, TFlagOptions extends FlagOptions, TFlagsResult extends ParseFlagsContext>(argsOrCtx: string[] | TFlagsResult, opts?: ParseFlagsOptions<TFlagOptions>): TFlagsResult & ParseFlagsContext<TFlags, TFlagOptions>;
|