feat: add simple list command
This commit is contained in:
parent
81e6b21253
commit
760239ff9b
2 changed files with 26 additions and 0 deletions
19
src/commands/list.ts
Normal file
19
src/commands/list.ts
Normal 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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
Reference in a new issue