diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7bb43a..5587ee4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,9 +3,9 @@ name: CI on: push: tags: - - '*' + - "*" branches: - - '*' + - "*" pull_request: branches: [master] @@ -13,7 +13,7 @@ jobs: test: strategy: matrix: - deno-version: [1.12.0] + deno-version: [2.x] runs-on: ubuntu-latest steps: diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..9cf9495 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..8ec9c55 --- /dev/null +++ b/deno.json @@ -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" + } +} diff --git a/mod.ts b/mod.ts index b3bef41..a062a6b 100644 --- a/mod.ts +++ b/mod.ts @@ -1,5 +1,5 @@ -import { parse } from "https://deno.land/std@0.103.0/flags/mod.ts"; -import { sprintf } from "https://deno.land/std@0.103.0/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) => { diff --git a/test.ts b/test.ts index dd8a878..cc4d6af 100644 --- a/test.ts +++ b/test.ts @@ -4,7 +4,8 @@ import { assertEquals, assertThrows, } from "https://deno.land/std@0.103.0/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, debug = false): Cmd { const d = {