-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved to minimist, since parseArgs from @std/cli doesn't support
multiple same flag arguments.
- Loading branch information
Showing
5 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true | ||
}, | ||
"name": "@aricart/cobra", | ||
"version": "0.0.9-1", | ||
"exports": { | ||
".": "./mod.ts" | ||
}, | ||
"publish": { | ||
"include": [ | ||
"./**/*" | ||
], | ||
"exclude": [ | ||
"./test.ts" | ||
] | ||
}, | ||
"imports": { | ||
"@std/fmt": "jsr:@std/fmt@^1.0.3", | ||
"minimist": "npm:minimist@^1.2.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
import { sprintf } from "https://deno.land/[email protected]/fmt/printf.ts"; | ||
import parseArgs from "minimist"; | ||
import { sprintf } from "@std/fmt/printf"; | ||
|
||
export interface Flag { | ||
type: "string" | "boolean" | "number"; | ||
|
@@ -138,15 +138,15 @@ export class Command implements Cmd { | |
this.cmd = cmd; | ||
} | ||
|
||
get use() { | ||
get use(): string { | ||
return this.cmd.use; | ||
} | ||
|
||
get long() { | ||
get long(): string | undefined { | ||
return this.cmd.long; | ||
} | ||
|
||
get short() { | ||
get short(): string | undefined { | ||
return this.cmd.short; | ||
} | ||
|
||
|
@@ -276,7 +276,7 @@ export class Command implements Cmd { | |
} | ||
return exit; | ||
} catch (err) { | ||
cmd.stderr(`${err.message}\n`); | ||
cmd.stderr(`${(err as Error).message}\n`); | ||
if (cmd.showHelp) { | ||
cmd.help(); | ||
} | ||
|
@@ -343,9 +343,9 @@ export class RootCommand extends Command implements Execute { | |
}); | ||
} | ||
matchCmd(args: string[]): [Command, string[]] { | ||
const argv = parse(args, { "--": true }); | ||
const argv = parseArgs(args, { "--": true }); | ||
let cmd = this as Command; | ||
const a = (argv._ ?? []).map((v) => { | ||
const a = (argv._ ?? []).map((v: unknown) => { | ||
return `${v}`; | ||
}); | ||
|
||
|
@@ -406,7 +406,7 @@ export class RootCommand extends Command implements Execute { | |
} | ||
}); | ||
|
||
const argv = parse(args, parseOpts); | ||
const argv = parseArgs(args, parseOpts); | ||
argv._ = a; | ||
|
||
flags.forEach((f) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ import { | |
assertEquals, | ||
assertThrows, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { cli, Cmd, Command, Flags } from "./mod.ts"; | ||
import { cli } from "./mod.ts"; | ||
import type { Cmd, Command, Flags } from "./mod.ts"; | ||
|
||
export function buildCmd(v: Partial<Cmd>, debug = false): Cmd { | ||
const d = { | ||
|