mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Replace minimist with arg for permissive feature
The npm package arg is more flexible than the old arguments parser minimist. The arg can left the unknown option unchanged, (while there is a bug that splits the unknown short options,) and stop at positional arguments are supported, too.
This commit is contained in:
parent
b4ebaf5186
commit
d5173c0773
4 changed files with 35 additions and 11 deletions
|
@ -12,13 +12,13 @@
|
|||
"stream": "stream-browserify"
|
||||
},
|
||||
"dependencies": {
|
||||
"arg": "^5.0.2",
|
||||
"cleanslate": "^0.10.1",
|
||||
"csp-serdes": "github:cmcaine/csp-serdes",
|
||||
"css": "^3.0.0",
|
||||
"editor-adapter": "^0.0.3",
|
||||
"esbuild": "^0.14.47",
|
||||
"fuse.js": "^6.6.2",
|
||||
"minimist": "^1.2.6",
|
||||
"nearley": "^2.20.1",
|
||||
"ramda": "^0.28.0",
|
||||
"semver-compare": "^1.0.0",
|
||||
|
|
|
@ -96,7 +96,7 @@ import semverCompare from "semver-compare"
|
|||
import * as hint_util from "@src/lib/hint_util"
|
||||
import { OpenMode } from "@src/lib/hint_util"
|
||||
import * as Proxy from "@src/lib/proxy"
|
||||
import minimist from "minimist"
|
||||
import * as arg from "@src/lib/arg_util"
|
||||
|
||||
/**
|
||||
* This is used to drive some excmd handling in `composite`.
|
||||
|
@ -1461,17 +1461,20 @@ export function find(...args: string[]) {
|
|||
//#content
|
||||
export function findnext(...args: string[]) {
|
||||
let n = 1
|
||||
const option = minimist(args, {
|
||||
boolean: Array.from("f?"),
|
||||
alias: {
|
||||
f: ["search-from-view", "searchFromView"],
|
||||
"?": "reverse",
|
||||
const option = arg.lib(
|
||||
{
|
||||
"--search-from-view": Boolean,
|
||||
"--searchFromView": "--search-from-view",
|
||||
"-f": "--search-from-view",
|
||||
|
||||
"--reverse": Boolean,
|
||||
"-?": "--reverse",
|
||||
},
|
||||
default: { f: false, "?": false },
|
||||
})
|
||||
{ argv: args },
|
||||
)
|
||||
if (option._.length > 0) n = Number(option._[0])
|
||||
if (option.reverse) n = -n
|
||||
return finding.jumpToNextMatch(n, option.searchFromView)
|
||||
if (option["--reverse"]) n = -n
|
||||
return finding.jumpToNextMatch(n, Boolean(option["--search-from-view"]))
|
||||
}
|
||||
|
||||
//#content
|
||||
|
|
16
src/lib/arg_util.ts
Normal file
16
src/lib/arg_util.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import arg from "arg"
|
||||
|
||||
export const name = "arg"
|
||||
export const lib = arg
|
||||
export function correctSingleHyphen(argv, ...singleNames) {
|
||||
return argv.map(arg => {
|
||||
const scan = arg.match(/^-[\w-]{2,}/)
|
||||
if (!scan) return arg
|
||||
const index = singleNames.indexOf(scan[0])
|
||||
if (index === -1) return arg
|
||||
else return "-" + arg
|
||||
})
|
||||
}
|
||||
export function isLastDoubleHyphen(argv) {
|
||||
return argv.at(-1) === "--"
|
||||
}
|
|
@ -1242,6 +1242,11 @@ anymatch@^3.0.3:
|
|||
normalize-path "^3.0.0"
|
||||
picomatch "^2.0.4"
|
||||
|
||||
arg@^5.0.2:
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.2.tgz#c81433cc427c92c4dcf4865142dbca6f15acd59c"
|
||||
integrity sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==
|
||||
|
||||
argparse@^1.0.7:
|
||||
version "1.0.10"
|
||||
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
|
||||
|
|
Loading…
Add table
Reference in a new issue