Skip to content

Commit

Permalink
feat(cli,daemon): Support pet name paths in kill command
Browse files Browse the repository at this point in the history
Adds support for dot-delimited pet name paths to the `kill`
command. Makes requisite changes to handle paths and lookup
formulas in the mailbox `terminate()` method.
  • Loading branch information
rekmarks committed Feb 7, 2024
1 parent 719705d commit f0aefd8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/commands/kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import os from 'os';
import { E } from '@endo/far';
import { withEndoParty } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';

export const killCommand = async ({ name, partyNames }) =>
withEndoParty(partyNames, { os, process }, async ({ party }) => {
await E(party).terminate(name);
await E(party).terminate(parsePetNamePath(name));
});
31 changes: 26 additions & 5 deletions packages/daemon/src/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { E } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
import { makeChangeTopic } from './pubsub.js';
import { makeIteratorRef } from './reader-ref.js';
import { assertPetName } from './pet-name.js';
import { assertPetName, petNamePathFrom } from './pet-name.js';

const { quote: q } = assert;

Expand Down Expand Up @@ -60,11 +60,32 @@ export const makeMailboxMaker = ({
);
};

const terminate = async petName => {
const formulaIdentifier = lookupFormulaIdentifierForName(petName);
if (formulaIdentifier === undefined) {
throw new TypeError(`Unknown pet name: ${q(petName)}`);
/**
* @param {string | string[]} petNameOrPath - A pet name or a sequence of pet names.
* @returns {Promise<void>} A promise that resolves when the name is terminated.
*/
const terminate = async petNameOrPath => {
const petNamePath = petNamePathFrom(petNameOrPath);
console.log(`trace:terminate1: ${petNamePath.join(', ')}`);

let formulaIdentifier;
if (petNamePath.length === 1) {
formulaIdentifier = lookupFormulaIdentifierForName(petNamePath[0]);
if (formulaIdentifier === undefined) {
throw new TypeError(`Unknown pet name: ${q(petNamePath[0])}`);
}
} else {
// eslint-disable-next-line no-use-before-define
const { value } = await provideLookupFormula(petNamePath);
// eslint-disable-next-line no-use-before-define
[formulaIdentifier] = await reverseLookup(value);
if (formulaIdentifier === undefined) {
throw new TypeError(
`Value at ${q(petNamePath.join(', '))} cannot be terminated.`,
);
}
}

// Behold, recursion:
// eslint-disable-next-line no-use-before-define
const controller = await provideControllerForFormulaIdentifier(
Expand Down

0 comments on commit f0aefd8

Please sign in to comment.