Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/agent/CommandStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class CommandStatus extends CommandPolykey {
clientPort: response.clientPort,
agentHost: response.agentHost,
agentPort: response.agentPort,
publicKeyJWK: response.publicKeyJwk,
certChainPEM: response.certChainPEM,
Comment thread
addievo marked this conversation as resolved.
},
}),
);
Expand Down
38 changes: 18 additions & 20 deletions src/nodes/CommandClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,25 @@ class CommandClaim extends CommandPolykey {
);
const claimed = response.success;
if (claimed) {
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [
`Successfully generated a cryptolink claim on Keynode with ID ${nodesUtils.encodeNodeId(
nodeId,
)}`,
],
}),
);
const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [
`Successfully generated a cryptolink claim on Keynode with ID ${nodesUtils.encodeNodeId(
nodeId,
)}`,
],
});
process.stdout.write(formattedOutput);
} else {
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [
`Successfully sent Gestalt Invite notification to Keynode with ID ${nodesUtils.encodeNodeId(
nodeId,
)}`,
],
}),
);
const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [
`Successfully sent Gestalt Invite notification to Keynode with ID ${nodesUtils.encodeNodeId(
nodeId,
)}`,
],
});
process.stdout.write(formattedOutput);
}
} finally {
if (pkClient! != null) await pkClient.stop();
Expand Down
54 changes: 30 additions & 24 deletions src/nodes/CommandConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,41 @@ class CommandAdd extends CommandPolykey {
});
const connectionEntries: Array<NodeConnectionMessage> = [];
for await (const connection of connections) {
connectionEntries.push(connection);
connectionEntries.push({
host: connection.host,
hostname: connection.hostname,
nodeIdEncoded: connection.nodeIdEncoded,
port: connection.port,
timeout: connection.timeout,
usageCount: connection.usageCount,
});
}
return connectionEntries;
}, auth);
if (options.format === 'human') {
const output: Array<string> = [];
for (const connection of connections) {
const hostnameString =
connection.hostname === '' ? '' : `(${connection.hostname})`;
const hostString = `${connection.nodeIdEncoded}@${connection.host}${hostnameString}:${connection.port}`;
const usageCount = connection.usageCount;
const timeout =
connection.timeout === -1 ? 'NA' : `${connection.timeout}`;
const outputLine = `${hostString}\t${usageCount}\t${timeout}`;
output.push(outputLine);
}
process.stdout.write(
binUtils.outputFormatter({
type: 'list',
data: output,
}),
);
// Wait for outputFormatter to complete and then write to stdout
const formattedOutput = await binUtils.outputFormatter({
type: 'table',
data: connections,
options: {
headers: [
'host',
'hostname',
'nodeIdEncoded',
'port',
'timeout',
'usageCount',
],
},
});
process.stdout.write(formattedOutput);
} else {
process.stdout.write(
binUtils.outputFormatter({
type: 'json',
data: connections,
}),
);
// Wait for outputFormatter to complete and then write to stdout
const formattedOutput = await binUtils.outputFormatter({
type: 'json',
data: connections,
});
process.stdout.write(formattedOutput);
}
} finally {
if (pkClient! != null) await pkClient.stop();
Expand Down
11 changes: 5 additions & 6 deletions src/nodes/CommandFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ class CommandFind extends CommandPolykey {
}
let output: any = result;
if (options.format === 'human') output = [result.message];
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
}),
);
const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
});
process.stdout.write(formattedOutput);
// Like ping it should error when failing to find node for automation reasons.
if (!result.success) {
throw new errors.ErrorPolykeyCLINodeFindFailed(result.message);
Expand Down
11 changes: 5 additions & 6 deletions src/nodes/CommandGetAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ class CommandGetAll extends CommandPolykey {
`NodeId ${value.nodeIdEncoded}, Address ${value.host}:${value.port}, bucketIndex ${value.bucketIndex}`,
);
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
}),
);
const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
});
process.stdout.write(formattedOutput);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
12 changes: 6 additions & 6 deletions src/nodes/CommandPing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class CommandPing extends CommandPolykey {
else status.message = error.message;
const output: any =
options.format === 'json' ? status : [status.message];
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
}),
);
const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
});
process.stdout.write(formattedOutput);

if (error != null) throw error;
} finally {
if (pkClient! != null) await pkClient.stop();
Expand Down
11 changes: 5 additions & 6 deletions src/notifications/CommandRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ class CommandRead extends CommandPolykey {
notifications.push(notification);
}
for (const notification of notifications) {
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'dict',
data: notification,
}),
);
const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'dict',
data: notification,
});
process.stdout.write(formattedOutput);
}
} finally {
if (pkClient! != null) await pkClient.stop();
Expand Down
11 changes: 5 additions & 6 deletions src/secrets/CommandGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ class CommandGet extends CommandPolykey {
meta,
);
const secretContent = Buffer.from(response.secretContent, 'binary');
process.stdout.write(
binUtils.outputFormatter({
type: 'raw',
data: secretContent,
}),
);
const formattedOutput = await binUtils.outputFormatter({
type: 'raw',
data: secretContent,
});
process.stdout.write(formattedOutput);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
13 changes: 7 additions & 6 deletions src/secrets/CommandList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ class CommandList extends CommandPolykey {
}
return data;
}, auth);
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: data,
}),
);

const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: data,
});

process.stdout.write(formattedOutput);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
14 changes: 7 additions & 7 deletions src/secrets/CommandStat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class CommandStat extends CommandPolykey {
data.push(`${key}: ${value}`);
}

// Print out the result.
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data,
}),
);
// Assuming the surrounding function is async
const formattedOutput = await binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data,
});

process.stdout.write(formattedOutput);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@ type AgentChildProcessOutput =
error: POJO;
};

type TableRow = Record<string, any>;

interface TableOptions {
headers?: string[];
includeRowCount?: boolean;
}

export type {
AgentStatusLiveData,
AgentChildProcessInput,
AgentChildProcessOutput,
TableRow,
TableOptions,
};
Loading