Skip to content

Commit

Permalink
Additional dot-delimited petname path support (#2296)
Browse files Browse the repository at this point in the history
Ref: #2023 

Adds support for dot-delimited petname paths in the `bundle`, `cat`,
`follow`, `open`, and `run` commands. Cleans up handling in the `list`
command.
  • Loading branch information
FUDCo authored May 24, 2024
2 parents 0a91fbe + 254459c commit 0db5815
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/cli/src/commands/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { E } from '@endo/far';
import bundleSource from '@endo/bundle-source';
import { makeReaderRef } from '@endo/daemon';
import { withEndoAgent } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';

const textEncoder = new TextEncoder();

Expand All @@ -22,11 +23,13 @@ export const bundleCommand = async ({
format: 'endoZipBase64',
})
);
assert(bundleName === undefined || typeof bundleName === 'string');
const bundlePath = bundleName && parsePetNamePath(bundleName);
process.stdout.write(`${bundle.endoZipBase64Sha512}\n`);
const bundleText = JSON.stringify(bundle);
const bundleBytes = textEncoder.encode(bundleText);
const readerRef = makeReaderRef([bundleBytes]);
return withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
await E(agent).storeBlob(readerRef, bundleName);
await E(agent).storeBlob(readerRef, bundlePath);
});
};
3 changes: 2 additions & 1 deletion packages/cli/src/commands/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import os from 'os';
import { E } from '@endo/far';
import { makeRefReader } from '@endo/daemon';
import { withEndoAgent } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';

export const cat = async ({ name, agentNames }) =>
withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
const readable = await E(agent).lookup(name);
const readable = await E(agent).lookup(...parsePetNamePath(name));
const readerRef = E(readable).streamBase64();
const reader = makeRefReader(readerRef);
for await (const chunk of reader) {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import os from 'os';
import { E } from '@endo/far';
import { makeRefIterator } from '@endo/daemon';
import { withEndoAgent } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';

export const followCommand = async ({ name, agentNames }) =>
withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
const iterable = await E(agent).lookup(name);
const iterable = await E(agent).lookup(...parsePetNamePath(name));
for await (const iterand of makeRefIterator(iterable)) {
console.log(iterand);
}
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import os from 'os';
import { E } from '@endo/far';
import { makeRefIterator } from '@endo/daemon';
import { withEndoHost } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';

export const list = async ({ directoryPath, follow, json }) =>
export const list = async ({ directory, follow, json }) =>
withEndoHost({ os, process }, async ({ host: agent }) => {
if (directoryPath !== undefined) {
agent = E(agent).lookup(...directoryPath.split('.'));
if (directory !== undefined) {
const directoryPath = parsePetNamePath(directory);
agent = E(agent).lookup(...directoryPath);
}
if (follow) {
const topic = await E(agent).followNameChanges();
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const makeCommand = async ({
return;
}

assert(resultName === undefined || typeof resultName === 'string');
const resultPath = resultName && parsePetNamePath(resultName);

/** @type {import('@endo/eventual-send').FarRef<import('@endo/stream').Reader<string>> | undefined} */
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import openWebPage from 'open';
import { E } from '@endo/far';

import { withEndoAgent } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';

export const open = async ({ webletName, agentNames }) => {
await withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
const weblet = E(agent).lookup(webletName);
const weblet = E(agent).lookup(...parsePetNamePath(webletName));
const webletLocation = await E(weblet).getLocation();
process.stdout.write(`${webletLocation}\n`);
openWebPage(webletLocation);
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { M } from '@endo/patterns';
import bundleSource from '@endo/bundle-source';

import { withEndoAgent } from '../context.js';
import { parsePetNamePath } from '../pet-name.js';

const endowments = harden({
assert,
Expand Down Expand Up @@ -86,7 +87,8 @@ export const run = async ({
args.unshift(filePath);
}

const readableP = E(agent).lookup(bundleName);
const bundleNamePath = parsePetNamePath(bundleName);
const readableP = E(agent).lookup(...bundleNamePath);
const bundleText = await E(readableP).text();
bundle = JSON.parse(bundleText);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/endo.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ export const main = async rawArgs => {
.description('show names known to the current or specified directory')
.option('-f,--follow', 'Follow updates')
.option('-j,--json', 'JSON format output')
.action(async (directoryPath, cmd) => {
.action(async (directory, cmd) => {
const { follow, json } = cmd.opts();
const { list } = await import('./commands/list.js');
return list({ directoryPath, follow, json });
return list({ directory, follow, json });
});

program
Expand Down

0 comments on commit 0db5815

Please sign in to comment.