Archived
0
0
Fork 0

feat: add simple list command

This commit is contained in:
Daryl Ronningen 2022-09-02 21:46:09 -07:00
parent 81e6b21253
commit 760239ff9b
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
2 changed files with 26 additions and 0 deletions

19
src/commands/list.ts Normal file
View file

@ -0,0 +1,19 @@
import * as lowdb from 'lowdb';
import { dbData } from './install.js';
export default class List {
public async run(): Promise<void> {
const dbFile = '/var/lib/wahpkg/pkgs.json';
const adapter = new lowdb.JSONFile<dbData>(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);
}
}

View file

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