Skip to content

Commit

Permalink
moved to minimist, since parseArgs from @std/cli doesn't support
Browse files Browse the repository at this point in the history
multiple same flag arguments.
  • Loading branch information
aricart committed Nov 1, 2024
1 parent 30939e3 commit cfdf4a6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name: CI
on:
push:
tags:
- '*'
- "*"
branches:
- '*'
- "*"
pull_request:
branches: [master]

jobs:
test:
strategy:
matrix:
deno-version: [1.12.0]
deno-version: [2.x]

runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
22 changes: 22 additions & 0 deletions deno.json
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"
}
}
18 changes: 9 additions & 9 deletions mod.ts
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";
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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}`;
});

Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit cfdf4a6

Please sign in to comment.