@outputai/cli 0.8.2-next.c12766f.0 → 0.8.2-next.e1cd79b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/docker/docker-compose-dev.yml +1 -1
- package/dist/commands/workflow/cost.d.ts +2 -3
- package/dist/commands/workflow/cost.js +11 -4
- package/dist/commands/workflow/cost.spec.js +3 -1
- package/dist/commands/workflow/dataset/list.d.ts +1 -3
- package/dist/commands/workflow/dataset/list.js +14 -10
- package/dist/commands/workflow/debug.d.ts +6 -2
- package/dist/commands/workflow/debug.js +29 -10
- package/dist/commands/workflow/debug.spec.js +5 -2
- package/dist/commands/workflow/list.d.ts +1 -4
- package/dist/commands/workflow/list.js +19 -15
- package/dist/commands/workflow/list.spec.js +1 -2
- package/dist/commands/workflow/result.d.ts +4 -3
- package/dist/commands/workflow/result.js +15 -6
- package/dist/commands/workflow/result.spec.js +4 -2
- package/dist/commands/workflow/run.d.ts +2 -3
- package/dist/commands/workflow/run.js +11 -4
- package/dist/commands/workflow/run.spec.js +3 -1
- package/dist/commands/workflow/runs/list.d.ts +1 -3
- package/dist/commands/workflow/runs/list.js +15 -11
- package/dist/commands/workflow/status.d.ts +4 -3
- package/dist/commands/workflow/status.js +30 -20
- package/dist/commands/workflow/status.spec.js +4 -2
- package/dist/commands/workflow/test_eval.d.ts +2 -3
- package/dist/commands/workflow/test_eval.js +15 -5
- package/dist/generated/framework_version.json +1 -1
- package/dist/hooks/init.d.ts +0 -1
- package/dist/hooks/init.js +30 -40
- package/dist/hooks/init.spec.js +4 -28
- package/dist/utils/constants.d.ts +5 -0
- package/dist/utils/constants.js +4 -0
- package/dist/utils/format_workflow_result.spec.js +13 -0
- package/dist/utils/output_formatter.d.ts +2 -0
- package/dist/utils/output_formatter.js +11 -0
- package/dist/utils/trace_formatter.js +2 -1
- package/oclif.manifest.json +101 -82
- package/package.json +4 -4
- package/dist/commands/workflow/test_eval.spec.d.ts +0 -1
- package/dist/commands/workflow/test_eval.spec.js +0 -84
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
|
-
import { WorkflowStatusResponse } from '#api/generated/api.js';
|
|
3
2
|
export default class WorkflowStatus extends Command {
|
|
4
3
|
static description: string;
|
|
5
|
-
static enableJsonFlag: boolean;
|
|
6
4
|
static examples: string[];
|
|
7
5
|
static args: {
|
|
8
6
|
workflowId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
9
7
|
};
|
|
10
|
-
|
|
8
|
+
static flags: {
|
|
9
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
11
12
|
catch(error: Error): Promise<void>;
|
|
12
13
|
}
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import { Args, Command } from '@oclif/core';
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
2
|
import { getWorkflowIdStatus } from '#api/generated/api.js';
|
|
3
|
+
import { OUTPUT_FORMAT } from '#utils/constants.js';
|
|
4
|
+
import { formatOutput } from '#utils/output_formatter.js';
|
|
3
5
|
import { handleApiError } from '#utils/error_handler.js';
|
|
4
6
|
import { normalizeWorkflowStatus } from '#utils/normalize_workflow_status.js';
|
|
5
|
-
function formatStatusText(result) {
|
|
6
|
-
const lines = [
|
|
7
|
-
`Workflow ID: ${result.workflowId || 'unknown'}`,
|
|
8
|
-
`Status: ${result.status || 'unknown'}`,
|
|
9
|
-
''
|
|
10
|
-
];
|
|
11
|
-
if (result.startedAt) {
|
|
12
|
-
lines.push(`Started At: ${new Date(result.startedAt).toISOString()}`);
|
|
13
|
-
}
|
|
14
|
-
if (result.completedAt) {
|
|
15
|
-
lines.push(`Completed At: ${new Date(result.completedAt).toISOString()}`);
|
|
16
|
-
}
|
|
17
|
-
return lines.join('\n');
|
|
18
|
-
}
|
|
19
7
|
export default class WorkflowStatus extends Command {
|
|
20
8
|
static description = 'Get workflow execution status';
|
|
21
|
-
static enableJsonFlag = true;
|
|
22
9
|
static examples = [
|
|
23
10
|
'<%= config.bin %> <%= command.id %> wf-12345',
|
|
24
|
-
'<%= config.bin %> <%= command.id %> wf-12345 --json'
|
|
11
|
+
'<%= config.bin %> <%= command.id %> wf-12345 --format json'
|
|
25
12
|
];
|
|
26
13
|
static args = {
|
|
27
14
|
workflowId: Args.string({
|
|
@@ -29,8 +16,16 @@ export default class WorkflowStatus extends Command {
|
|
|
29
16
|
required: true
|
|
30
17
|
})
|
|
31
18
|
};
|
|
19
|
+
static flags = {
|
|
20
|
+
format: Flags.string({
|
|
21
|
+
char: 'f',
|
|
22
|
+
description: 'Output format',
|
|
23
|
+
options: [OUTPUT_FORMAT.JSON, OUTPUT_FORMAT.TEXT],
|
|
24
|
+
default: OUTPUT_FORMAT.TEXT
|
|
25
|
+
})
|
|
26
|
+
};
|
|
32
27
|
async run() {
|
|
33
|
-
const { args } = await this.parse(WorkflowStatus);
|
|
28
|
+
const { args, flags } = await this.parse(WorkflowStatus);
|
|
34
29
|
this.log(`Fetching status for workflow: ${args.workflowId}...`);
|
|
35
30
|
const response = await getWorkflowIdStatus(args.workflowId);
|
|
36
31
|
if (!response || !response.data) {
|
|
@@ -41,8 +36,23 @@ export default class WorkflowStatus extends Command {
|
|
|
41
36
|
...rawData,
|
|
42
37
|
status: normalizeWorkflowStatus(rawData.status)
|
|
43
38
|
};
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const output = formatOutput(data, flags.format, (result) => {
|
|
40
|
+
const lines = [
|
|
41
|
+
`Workflow ID: ${result.workflowId || 'unknown'}`,
|
|
42
|
+
`Status: ${result.status || 'unknown'}`,
|
|
43
|
+
''
|
|
44
|
+
];
|
|
45
|
+
if (result.startedAt) {
|
|
46
|
+
const startDate = new Date(result.startedAt);
|
|
47
|
+
lines.push(`Started At: ${startDate.toISOString()}`);
|
|
48
|
+
}
|
|
49
|
+
if (result.completedAt) {
|
|
50
|
+
const completedDate = new Date(result.completedAt);
|
|
51
|
+
lines.push(`Completed At: ${completedDate.toISOString()}`);
|
|
52
|
+
}
|
|
53
|
+
return lines.join('\n');
|
|
54
|
+
});
|
|
55
|
+
this.log(`\n${output}`);
|
|
46
56
|
}
|
|
47
57
|
async catch(error) {
|
|
48
58
|
return handleApiError(error, (...args) => this.error(...args), {
|
|
@@ -22,10 +22,12 @@ describe('workflow status command', () => {
|
|
|
22
22
|
expect(WorkflowStatus).toBeDefined();
|
|
23
23
|
expect(WorkflowStatus.description).toContain('Get workflow execution status');
|
|
24
24
|
expect(WorkflowStatus.args).toHaveProperty('workflowId');
|
|
25
|
+
expect(WorkflowStatus.flags).toHaveProperty('format');
|
|
25
26
|
});
|
|
26
|
-
it('
|
|
27
|
+
it('should have correct flag configuration', async () => {
|
|
27
28
|
const WorkflowStatus = (await import('./status.js')).default;
|
|
28
|
-
expect(WorkflowStatus.
|
|
29
|
+
expect(WorkflowStatus.flags.format.options).toEqual(['json', 'text']);
|
|
30
|
+
expect(WorkflowStatus.flags.format.default).toBe('text');
|
|
29
31
|
});
|
|
30
32
|
});
|
|
31
33
|
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
|
-
import type { EvalOutput } from '@outputai/evals';
|
|
3
2
|
export default class WorkflowTest extends Command {
|
|
4
3
|
static aliases: string[];
|
|
5
4
|
static description: string;
|
|
6
|
-
static enableJsonFlag: boolean;
|
|
7
5
|
static examples: string[];
|
|
8
6
|
static args: {
|
|
9
7
|
workflowName: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
@@ -12,8 +10,9 @@ export default class WorkflowTest extends Command {
|
|
|
12
10
|
cached: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
11
|
save: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
12
|
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
14
|
};
|
|
16
|
-
run(): Promise<
|
|
15
|
+
run(): Promise<void>;
|
|
17
16
|
private ensureEvalWorkflowRegistered;
|
|
18
17
|
private validateDatasets;
|
|
19
18
|
private runWorkflowForDatasets;
|
|
@@ -9,13 +9,12 @@ import { getEvalWorkflowName, renderEvalOutput, computeExitCode, EvalOutputSchem
|
|
|
9
9
|
export default class WorkflowTest extends Command {
|
|
10
10
|
static aliases = ['workflow:test'];
|
|
11
11
|
static description = 'Run evaluations against a workflow using its datasets';
|
|
12
|
-
static enableJsonFlag = true;
|
|
13
12
|
static examples = [
|
|
14
13
|
'<%= config.bin %> <%= command.id %> simple',
|
|
15
14
|
'<%= config.bin %> <%= command.id %> simple --cached',
|
|
16
15
|
'<%= config.bin %> <%= command.id %> simple --save',
|
|
17
16
|
'<%= config.bin %> <%= command.id %> simple --dataset basic_input,edge_case',
|
|
18
|
-
'<%= config.bin %> <%= command.id %> simple --json'
|
|
17
|
+
'<%= config.bin %> <%= command.id %> simple --format json'
|
|
19
18
|
];
|
|
20
19
|
static args = {
|
|
21
20
|
workflowName: Args.string({
|
|
@@ -37,6 +36,12 @@ export default class WorkflowTest extends Command {
|
|
|
37
36
|
dataset: Flags.string({
|
|
38
37
|
description: 'Comma-separated list of dataset names to run',
|
|
39
38
|
char: 'd'
|
|
39
|
+
}),
|
|
40
|
+
format: Flags.string({
|
|
41
|
+
char: 'f',
|
|
42
|
+
description: 'Output format',
|
|
43
|
+
options: ['json', 'text'],
|
|
44
|
+
default: 'text'
|
|
40
45
|
})
|
|
41
46
|
};
|
|
42
47
|
async run() {
|
|
@@ -67,11 +72,16 @@ export default class WorkflowTest extends Command {
|
|
|
67
72
|
if (flags.save) {
|
|
68
73
|
await this.saveEvalResults(evalOutput, preparedDatasets, dir);
|
|
69
74
|
}
|
|
70
|
-
if (
|
|
75
|
+
if (flags.format === 'json') {
|
|
76
|
+
this.log(JSON.stringify(evalOutput, null, 2));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
71
79
|
this.log(renderEvalOutput(evalOutput, evalName));
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
const exitCode = computeExitCode(evalOutput);
|
|
82
|
+
if (exitCode !== 0) {
|
|
83
|
+
this.exit(exitCode);
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
86
|
async ensureEvalWorkflowRegistered(workflowName, evalName) {
|
|
77
87
|
const catalog = await fetchWorkflowCatalog().catch(() => null);
|
package/dist/hooks/init.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Hook } from '@oclif/core';
|
|
|
2
2
|
export declare const INTERACTIVE_FLAGS: string[];
|
|
3
3
|
export declare const GLOBAL_FLAGS: Set<string>;
|
|
4
4
|
export declare const hasInteractiveFlag: (argv: string[]) => boolean;
|
|
5
|
-
export declare const hasJsonFlag: (argv: string[]) => boolean;
|
|
6
5
|
export declare const stripGlobalFlags: (argv: string[]) => void;
|
|
7
6
|
declare const hook: Hook<'init'>;
|
|
8
7
|
export default hook;
|
package/dist/hooks/init.js
CHANGED
|
@@ -6,10 +6,6 @@ const debug = debugFactory('output-cli:init');
|
|
|
6
6
|
export const INTERACTIVE_FLAGS = ['--yes', '--non-interactive'];
|
|
7
7
|
export const GLOBAL_FLAGS = new Set(INTERACTIVE_FLAGS);
|
|
8
8
|
export const hasInteractiveFlag = (argv) => argv.some(arg => INTERACTIVE_FLAGS.includes(arg));
|
|
9
|
-
// The version banner must never reach stdout in JSON mode, where it would
|
|
10
|
-
// corrupt the machine-readable output. oclif only suppresses `this.log` inside
|
|
11
|
-
// the command, not hook output, so we detect `--json` ourselves.
|
|
12
|
-
export const hasJsonFlag = (argv) => argv.includes('--json');
|
|
13
9
|
export const stripGlobalFlags = (argv) => {
|
|
14
10
|
const kept = argv.filter(arg => !GLOBAL_FLAGS.has(arg));
|
|
15
11
|
if (kept.length !== argv.length) {
|
|
@@ -23,43 +19,37 @@ const hook = async function (opts) {
|
|
|
23
19
|
if (interactive) {
|
|
24
20
|
setNonInteractive(true);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
try {
|
|
23
|
+
// Only the local cache is read here; the registry roundtrip happens in a
|
|
24
|
+
// detached child so it never delays the invoked command.
|
|
25
|
+
const result = await readCachedResult(this.config.version, this.config.cacheDir);
|
|
26
|
+
if (!result) {
|
|
27
|
+
spawnBackgroundRefresh(this.config.version, this.config.cacheDir);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!result.updateAvailable) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const border = ux.colorize('dim', '─'.repeat(80));
|
|
34
|
+
const warning = ux.colorize('yellow', 'Uhoh! Your Output.ai CLI is behind!');
|
|
35
|
+
const latestVer = ux.colorize('green', `v${result.latestVersion}`);
|
|
36
|
+
const currentVer = ux.colorize('yellow', `v${result.currentVersion}`);
|
|
37
|
+
const updateCmd = ux.colorize('cyan', 'npx output update');
|
|
38
|
+
ux.stdout('');
|
|
39
|
+
ux.stdout(border);
|
|
40
|
+
ux.stdout('');
|
|
41
|
+
ux.stdout(` ⚠️ ${warning}`);
|
|
42
|
+
ux.stdout('');
|
|
43
|
+
ux.stdout(` Latest is ${latestVer}, and you're using ${currentVer}`);
|
|
44
|
+
ux.stdout('');
|
|
45
|
+
ux.stdout(` Run \`${updateCmd}\` to update`);
|
|
46
|
+
ux.stdout('');
|
|
47
|
+
ux.stdout(border);
|
|
48
|
+
ux.stdout('');
|
|
38
49
|
}
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
catch (error) {
|
|
51
|
+
// Never block CLI execution
|
|
52
|
+
debug('Version banner failed: %O', error);
|
|
41
53
|
}
|
|
42
|
-
// Skip the banner entirely in JSON mode: even on stderr it is pure noise to
|
|
43
|
-
// a script consuming the command's structured output.
|
|
44
|
-
if (hasJsonFlag(opts.argv) || hasJsonFlag(process.argv)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const border = ux.colorize('dim', '─'.repeat(80));
|
|
48
|
-
const warning = ux.colorize('yellow', 'Uhoh! Your Output.ai CLI is behind!');
|
|
49
|
-
const latestVer = ux.colorize('green', `v${result.latestVersion}`);
|
|
50
|
-
const currentVer = ux.colorize('yellow', `v${result.currentVersion}`);
|
|
51
|
-
const updateCmd = ux.colorize('cyan', 'npx output update');
|
|
52
|
-
// Advisory notice goes to stderr so stdout stays clean for piping in every mode.
|
|
53
|
-
ux.stderr('');
|
|
54
|
-
ux.stderr(border);
|
|
55
|
-
ux.stderr('');
|
|
56
|
-
ux.stderr(` ⚠️ ${warning}`);
|
|
57
|
-
ux.stderr('');
|
|
58
|
-
ux.stderr(` Latest is ${latestVer}, and you're using ${currentVer}`);
|
|
59
|
-
ux.stderr('');
|
|
60
|
-
ux.stderr(` Run \`${updateCmd}\` to update`);
|
|
61
|
-
ux.stderr('');
|
|
62
|
-
ux.stderr(border);
|
|
63
|
-
ux.stderr('');
|
|
64
54
|
};
|
|
65
55
|
export default hook;
|
package/dist/hooks/init.spec.js
CHANGED
|
@@ -12,12 +12,11 @@ vi.mock('#utils/interactive.js', () => ({
|
|
|
12
12
|
vi.mock('@oclif/core', () => ({
|
|
13
13
|
ux: {
|
|
14
14
|
stdout: vi.fn(),
|
|
15
|
-
stderr: vi.fn(),
|
|
16
15
|
colorize: vi.fn((_color, text) => text)
|
|
17
16
|
}
|
|
18
17
|
}));
|
|
19
18
|
import { ux } from '@oclif/core';
|
|
20
|
-
import hook, { hasInteractiveFlag,
|
|
19
|
+
import hook, { hasInteractiveFlag, stripGlobalFlags } from './init.js';
|
|
21
20
|
describe('init hook', () => {
|
|
22
21
|
beforeEach(() => {
|
|
23
22
|
vi.clearAllMocks();
|
|
@@ -25,7 +24,7 @@ describe('init hook', () => {
|
|
|
25
24
|
const createHookContext = (version = '0.8.4') => ({
|
|
26
25
|
config: { version, cacheDir: '/tmp/test-cache' }
|
|
27
26
|
});
|
|
28
|
-
it('should display warning
|
|
27
|
+
it('should display warning when cached result says an update is available', async () => {
|
|
29
28
|
vi.mocked(readCachedResult).mockResolvedValue({
|
|
30
29
|
updateAvailable: true,
|
|
31
30
|
currentVersion: '0.8.4',
|
|
@@ -35,25 +34,13 @@ describe('init hook', () => {
|
|
|
35
34
|
await hook.call(ctx, { argv: [], id: undefined });
|
|
36
35
|
expect(readCachedResult).toHaveBeenCalledWith('0.8.4', '/tmp/test-cache');
|
|
37
36
|
expect(spawnBackgroundRefresh).not.toHaveBeenCalled();
|
|
38
|
-
expect(ux.
|
|
39
|
-
|
|
40
|
-
const output = vi.mocked(ux.stderr).mock.calls.map(c => c[0]).join('\n');
|
|
37
|
+
expect(ux.stdout).toHaveBeenCalled();
|
|
38
|
+
const output = vi.mocked(ux.stdout).mock.calls.map(c => c[0]).join('\n');
|
|
41
39
|
expect(output).toContain('Uhoh');
|
|
42
40
|
expect(output).toContain('v1.0.0');
|
|
43
41
|
expect(output).toContain('v0.8.4');
|
|
44
42
|
expect(output).toContain('npx output update');
|
|
45
43
|
});
|
|
46
|
-
it('should suppress the warning entirely in JSON mode', async () => {
|
|
47
|
-
vi.mocked(readCachedResult).mockResolvedValue({
|
|
48
|
-
updateAvailable: true,
|
|
49
|
-
currentVersion: '0.8.4',
|
|
50
|
-
latestVersion: '1.0.0'
|
|
51
|
-
});
|
|
52
|
-
const ctx = createHookContext();
|
|
53
|
-
await hook.call(ctx, { argv: ['--json'], id: undefined });
|
|
54
|
-
expect(ux.stderr).not.toHaveBeenCalled();
|
|
55
|
-
expect(ux.stdout).not.toHaveBeenCalled();
|
|
56
|
-
});
|
|
57
44
|
it('should not display anything when up to date', async () => {
|
|
58
45
|
vi.mocked(readCachedResult).mockResolvedValue({
|
|
59
46
|
updateAvailable: false,
|
|
@@ -134,17 +121,6 @@ describe('init hook', () => {
|
|
|
134
121
|
expect(hasInteractiveFlag([])).toBe(false);
|
|
135
122
|
});
|
|
136
123
|
});
|
|
137
|
-
describe('hasJsonFlag', () => {
|
|
138
|
-
it('returns true when --json is present', () => {
|
|
139
|
-
expect(hasJsonFlag(['workflow', 'runs', 'list', '--json'])).toBe(true);
|
|
140
|
-
});
|
|
141
|
-
it('returns false when --json is absent', () => {
|
|
142
|
-
expect(hasJsonFlag(['workflow', 'runs', 'list', '--format', 'table'])).toBe(false);
|
|
143
|
-
});
|
|
144
|
-
it('returns false for an empty argv', () => {
|
|
145
|
-
expect(hasJsonFlag([])).toBe(false);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
124
|
describe('stripGlobalFlags', () => {
|
|
149
125
|
it('mutates argv in place to remove global flags', () => {
|
|
150
126
|
const argv = ['init', '--yes', 'foo', '--non-interactive'];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { formatWorkflowResult } from './format_workflow_result.js';
|
|
3
|
+
import { formatOutput } from './output_formatter.js';
|
|
3
4
|
describe('formatWorkflowResult', () => {
|
|
4
5
|
it('should display output for completed workflows', () => {
|
|
5
6
|
const result = formatWorkflowResult({
|
|
@@ -75,4 +76,16 @@ describe('formatWorkflowResult', () => {
|
|
|
75
76
|
expect(result).toContain('Status: failed');
|
|
76
77
|
expect(result).not.toContain('Error:');
|
|
77
78
|
});
|
|
79
|
+
it('should work with formatOutput for json format', () => {
|
|
80
|
+
const data = {
|
|
81
|
+
workflowId: 'wf-456',
|
|
82
|
+
status: 'failed',
|
|
83
|
+
output: null,
|
|
84
|
+
error: 'Activity task failed'
|
|
85
|
+
};
|
|
86
|
+
const output = formatOutput(data, 'json', formatWorkflowResult);
|
|
87
|
+
const parsed = JSON.parse(output);
|
|
88
|
+
expect(parsed.status).toBe('failed');
|
|
89
|
+
expect(parsed.error).toBe('Activity task failed');
|
|
90
|
+
});
|
|
78
91
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OUTPUT_FORMAT } from './constants.js';
|
|
2
|
+
export function formatOutput(result, format, textFormatter = result => JSON.stringify(result, null, 2)) {
|
|
3
|
+
switch (format) {
|
|
4
|
+
case OUTPUT_FORMAT.JSON:
|
|
5
|
+
return JSON.stringify(result, null, 2);
|
|
6
|
+
case OUTPUT_FORMAT.TEXT:
|
|
7
|
+
return textFormatter(result);
|
|
8
|
+
default:
|
|
9
|
+
return textFormatter(result);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Table from 'cli-table3';
|
|
2
2
|
import { ux } from '@oclif/core';
|
|
3
|
+
import { formatOutput } from '#utils/output_formatter.js';
|
|
3
4
|
import { formatDuration } from '#utils/date_formatter.js';
|
|
4
5
|
import { getErrorMessage } from '#utils/error_utils.js';
|
|
5
6
|
import { isTraceEvent, isValidTimestamp } from '#types/trace.js';
|
|
@@ -368,7 +369,7 @@ const formatAsText = (trace) => {
|
|
|
368
369
|
export function format(traceData, outputFormat = 'text') {
|
|
369
370
|
const trace = typeof traceData === 'string' ? JSON.parse(traceData) : traceData;
|
|
370
371
|
if (outputFormat === 'json') {
|
|
371
|
-
return
|
|
372
|
+
return formatOutput(trace, 'json');
|
|
372
373
|
}
|
|
373
374
|
return formatAsText(trace);
|
|
374
375
|
}
|