From 760239ff9ba404df79eb122f18fccf0a86961c41 Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Fri, 2 Sep 2022 21:46:09 -0700 Subject: [PATCH] feat: add simple list command --- src/commands/list.ts | 19 +++++++++++++++++++ src/index.ts | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 src/commands/list.ts diff --git a/src/commands/list.ts b/src/commands/list.ts new file mode 100644 index 0000000..85c6b62 --- /dev/null +++ b/src/commands/list.ts @@ -0,0 +1,19 @@ +import * as lowdb from 'lowdb'; + +import { dbData } from './install.js'; + +export default class List { + public async run(): Promise { + const dbFile = '/var/lib/wahpkg/pkgs.json'; + const adapter = new lowdb.JSONFile(dbFile); + const db = new lowdb.Low(adapter); + + await db.read(); + + for (const pkg of db.data.pkgs) { + console.log(`${pkg.name} ${pkg.version}`); + } + + process.exit(0); + } +} diff --git a/src/index.ts b/src/index.ts index a021354..51d9f43 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { Command } from 'commander'; import fs from 'node:fs'; import Install, { InstallOptions } from './commands/install.js'; +import List from './commands/list.js'; import Uninstall, { UninstallOptions } from './commands/uninstall.js'; if (process.getuid() !== 0) { @@ -43,4 +44,10 @@ program.command('uninstall') await new Uninstall(name, options).run(); }); +program.command('list') + .description('List installed packages') + .action(async () => { + await new List().run(); + }); + program.parse();