diff --git a/package.json b/package.json index 1bb81ec6..0b45dfcd 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,11 @@ "dependencies": { "anymatch": "^3.1.3", "chokidar": "^4.0.1", + "citty": "^0.1.6", "destr": "^2.0.3", "h3": "^1.13.0", "listhen": "^1.9.0", "lru-cache": "^10.4.3", - "mri": "^1.2.0", "node-fetch-native": "^1.6.4", "ofetch": "^1.4.1", "ufo": "^1.5.4" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 58d8d408..b078e576 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: chokidar: specifier: ^4.0.1 version: 4.0.1 + citty: + specifier: ^0.1.6 + version: 0.1.6 destr: specifier: ^2.0.3 version: 2.0.3 @@ -26,9 +29,6 @@ importers: lru-cache: specifier: ^10.4.3 version: 10.4.3 - mri: - specifier: ^1.2.0 - version: 1.2.0 node-fetch-native: specifier: ^1.6.4 version: 1.6.4 diff --git a/src/cli.ts b/src/cli.ts index 18f15146..dc3851bc 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,36 +1,40 @@ import { resolve } from "node:path"; -import mri from "mri"; +import { defineCommand, runMain } from "citty"; import { listen } from "listhen"; import { createStorage } from "./storage"; import { createStorageServer } from "./server"; import fsDriver from "./drivers/fs"; -async function main() { - const arguments_ = mri(process.argv.splice(2)); +const main = defineCommand({ + meta: { + name: "unstorage", + description: "Unstorage CLI", + }, + args: { + dir: { + type: "string", + description: "project root directory", + }, + _dir: { + type: "positional", + default: ".", + description: "project root directory (prefer using `--dir`)", + }, + }, + async run(args) { + const rootDir = resolve(args.args.dir || args.args._dir); - if (arguments_.help) { - console.log("Usage: npx unstorage [rootDir]"); - // eslint-disable-next-line unicorn/no-process-exit - process.exit(0); - } + const storage = createStorage({ + driver: fsDriver({ base: rootDir }), + }); - const rootDir = resolve(arguments_._[0] || "."); + const storageServer = createStorageServer(storage); - const storage = createStorage({ - driver: fsDriver({ base: rootDir }), - }); - - const storageServer = createStorageServer(storage); - - await listen(storageServer.handle, { - name: "Storage server", - port: 8080, - }); -} - -// eslint-disable-next-line unicorn/prefer-top-level-await -main().catch((error) => { - console.error(error); - // eslint-disable-next-line unicorn/no-process-exit - process.exit(1); + await listen(storageServer.handle, { + name: "unstorage server", + port: 8080, + }); + }, }); + +runMain(main);