dbn-cli 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/index.ts +35 -7
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbn-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A lightweight terminal-based database browser",
|
|
5
|
+
"repository": "https://github.com/amio/dbn-cli",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "src/index.ts",
|
|
7
8
|
"bin": {
|
|
8
|
-
"dbn": "
|
|
9
|
+
"dbn": "bin/dbn.ts"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
12
|
"test": "node --test --experimental-strip-types test/*.test.ts",
|
|
@@ -32,8 +33,7 @@
|
|
|
32
33
|
],
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/node": "^24.10.9"
|
|
35
|
-
}
|
|
36
|
-
,
|
|
36
|
+
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"string-width": "^5.0.1"
|
|
39
39
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stdin, stdout, exit } from 'node:process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import * as readline from 'node:readline';
|
|
4
4
|
import { SQLiteAdapter } from './adapter/sqlite.ts';
|
|
5
5
|
import { Screen } from './ui/screen.ts';
|
|
@@ -227,14 +227,42 @@ export class DBPeek {
|
|
|
227
227
|
* Main entry point
|
|
228
228
|
*/
|
|
229
229
|
export function main(args: string[]): void {
|
|
230
|
-
|
|
230
|
+
// Simple CLI parsing: support flags (-v/--version, -h/--help)
|
|
231
|
+
const flags = new Set(args.filter(a => a.startsWith('-')));
|
|
232
|
+
const dbPath = args.find(a => !a.startsWith('-'));
|
|
233
|
+
|
|
234
|
+
const printHelp = () => {
|
|
235
|
+
stdout.write(`Usage: dbn [options] <path-to-sqlite-db-file>\n\n`);
|
|
236
|
+
stdout.write(`Options:\n`);
|
|
237
|
+
stdout.write(` -h, --help Show help information\n`);
|
|
238
|
+
stdout.write(` -v, --version Show version\n\n`);
|
|
239
|
+
stdout.write(`Example:\n`);
|
|
240
|
+
stdout.write(` dbn ./mydatabase.db\n`);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const printVersion = () => {
|
|
244
|
+
try {
|
|
245
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { version?: string };
|
|
246
|
+
stdout.write((pkg.version ?? 'unknown') + '\n');
|
|
247
|
+
} catch {
|
|
248
|
+
stdout.write('unknown\n');
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
if (flags.has('-h') || flags.has('--help')) {
|
|
253
|
+
printHelp();
|
|
254
|
+
exit(0);
|
|
255
|
+
}
|
|
231
256
|
|
|
257
|
+
if (flags.has('-v') || flags.has('--version')) {
|
|
258
|
+
printVersion();
|
|
259
|
+
exit(0);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// If no db path provided, show help by default
|
|
232
263
|
if (!dbPath) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
console.error('Example:');
|
|
236
|
-
console.error(' dbn ./mydatabase.db');
|
|
237
|
-
exit(1);
|
|
264
|
+
printHelp();
|
|
265
|
+
exit(0);
|
|
238
266
|
}
|
|
239
267
|
|
|
240
268
|
const app = new DBPeek(dbPath);
|