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();