dbn-cli 0.2.4 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +35 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbn-cli",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "A lightweight terminal-based database browser",
5
5
  "repository": "https://github.com/amio/dbn-cli",
6
6
  "type": "module",
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
- const dbPath = args[0];
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
- console.error('Usage: dbn <path-to-sqlite-db-file>');
234
- console.error('');
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);