From e4dbc2797c49406bafc0a26ffd46b79c3ff95154 Mon Sep 17 00:00:00 2001 From: Aryan Jassal Date: Tue, 12 Nov 2024 14:45:50 +1100 Subject: [PATCH] feat: using logger for agent shutdown messages chore: change command for vaults delete to be rm|remove fix: updated tests fix: removed touch alias for vaults create --- src/agent/CommandStart.ts | 2 +- src/agent/CommandStop.ts | 6 +++--- src/vaults/CommandCreate.ts | 1 - src/vaults/{CommandDelete.ts => CommandRemove.ts} | 7 ++++--- src/vaults/CommandVaults.ts | 4 ++-- tests/vaults/{delete.test.ts => remove.test.ts} | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) rename src/vaults/{CommandDelete.ts => CommandRemove.ts} (93%) rename tests/vaults/{delete.test.ts => remove.test.ts} (94%) diff --git a/src/agent/CommandStart.ts b/src/agent/CommandStart.ts index 64c5c64d..88e64e96 100644 --- a/src/agent/CommandStart.ts +++ b/src/agent/CommandStart.ts @@ -253,7 +253,7 @@ class CommandStart extends CommandPolykey { pkAgent.addEventListener( polykeyEvents.EventPolykeyAgentStop.name, () => { - process.stderr.write('Stopping Agent\n'); + this.logger.warn('Stopping Agent'); }, { once: true }, ); diff --git a/src/agent/CommandStop.ts b/src/agent/CommandStop.ts index de9b1da1..cee40f90 100644 --- a/src/agent/CommandStop.ts +++ b/src/agent/CommandStop.ts @@ -27,10 +27,10 @@ class CommandStop extends CommandPolykey { ); const statusInfo = clientStatus.statusInfo; if (statusInfo?.status === 'DEAD') { - process.stderr.write('Agent is already dead\n'); + this.logger.warn('Agent is already dead'); return; } else if (statusInfo?.status === 'STOPPING') { - process.stderr.write('Agent is already stopping\n'); + this.logger.warn('Agent is already stopping'); return; } else if (statusInfo?.status === 'STARTING') { throw new errors.ErrorPolykeyCLIAgentStatus('Agent is starting'); @@ -62,7 +62,7 @@ class CommandStop extends CommandPolykey { }), auth, ); - process.stderr.write('Stopping Agent\n'); + this.logger.warn('Stopping Agent'); } finally { if (pkClient! != null) await pkClient.stop(); } diff --git a/src/vaults/CommandCreate.ts b/src/vaults/CommandCreate.ts index 163b37ac..56880db2 100644 --- a/src/vaults/CommandCreate.ts +++ b/src/vaults/CommandCreate.ts @@ -10,7 +10,6 @@ class CommandCreate extends CommandPolykey { constructor(...args: ConstructorParameters) { super(...args); this.name('create'); - this.aliases(['touch']); this.description('Create a new Vault'); this.argument( '', diff --git a/src/vaults/CommandDelete.ts b/src/vaults/CommandRemove.ts similarity index 93% rename from src/vaults/CommandDelete.ts rename to src/vaults/CommandRemove.ts index 8c06b6c0..04cc7172 100644 --- a/src/vaults/CommandDelete.ts +++ b/src/vaults/CommandRemove.ts @@ -8,11 +8,12 @@ import * as binParsers from '../utils/parsers'; class CommandDelete extends CommandPolykey { constructor(...args: ConstructorParameters) { super(...args); - this.name('delete'); - this.description('Delete an Existing Vault'); + this.name('rm'); + this.alias('remove'); + this.description('Remove an existing Vault'); this.argument( '', - 'Name of the vault to be deleted', + 'Name of the vault to be removed', binParsers.parseVaultName, ); this.addOption(binOptions.nodeId); diff --git a/src/vaults/CommandVaults.ts b/src/vaults/CommandVaults.ts index 2c9a5d47..7e433674 100644 --- a/src/vaults/CommandVaults.ts +++ b/src/vaults/CommandVaults.ts @@ -1,11 +1,11 @@ import CommandClone from './CommandClone'; import CommandCreate from './CommandCreate'; -import CommandDelete from './CommandDelete'; import CommandList from './CommandList'; import CommandLog from './CommandLog'; import CommandScan from './CommandScan'; import CommandPermissions from './CommandPermissions'; import CommandPull from './CommandPull'; +import CommandRemove from './CommandRemove'; import CommandRename from './CommandRename'; import CommandShare from './CommandShare'; import CommandUnshare from './CommandUnshare'; @@ -19,11 +19,11 @@ class CommandVaults extends CommandPolykey { this.description('Vaults Operations'); this.addCommand(new CommandClone(...args)); this.addCommand(new CommandCreate(...args)); - this.addCommand(new CommandDelete(...args)); this.addCommand(new CommandList(...args)); this.addCommand(new CommandLog(...args)); this.addCommand(new CommandPermissions(...args)); this.addCommand(new CommandPull(...args)); + this.addCommand(new CommandRemove(...args)); this.addCommand(new CommandRename(...args)); this.addCommand(new CommandShare(...args)); this.addCommand(new CommandUnshare(...args)); diff --git a/tests/vaults/delete.test.ts b/tests/vaults/remove.test.ts similarity index 94% rename from tests/vaults/delete.test.ts rename to tests/vaults/remove.test.ts index e33d2b85..0ddf5809 100644 --- a/tests/vaults/delete.test.ts +++ b/tests/vaults/remove.test.ts @@ -8,7 +8,7 @@ import * as ids from 'polykey/dist/ids'; import * as keysUtils from 'polykey/dist/keys/utils'; import * as testUtils from '../utils'; -describe('commandDeleteVault', () => { +describe('commandRemoveVault', () => { const password = 'password'; const logger = new Logger('CLI Test', LogLevel.WARN, [new StreamHandler()]); let dataDir: string; @@ -68,8 +68,8 @@ describe('commandDeleteVault', () => { }); }); - test('should delete vault', async () => { - command = ['vaults', 'delete', '-np', dataDir, vaultName]; + test('should remove vault', async () => { + command = ['vaults', 'rm', '-np', dataDir, vaultName]; await polykeyAgent.vaultManager.createVault(vaultName); let id = polykeyAgent.vaultManager.getVaultId(vaultName); expect(id).toBeTruthy();