From 4299098daf8d5b56fa49e39ab2a06c27ce317154 Mon Sep 17 00:00:00 2001 From: Muhammad Bin Zohaib Date: Wed, 18 Nov 2026 20:09:07 +0500 Subject: [PATCH 1/5] feat: read structured CLI inputs from JSON files --- src/commands.ts | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index a1c6ff1..3fbfe8e 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,3 +1,4 @@ +import { readFileSync } from 'node:fs'; import type { Command, OptionValues } from 'commander'; import { Command as CommandClass } from 'commander'; import type { MakeTool, JSONSchema } from '@makehq/sdk/tools'; @@ -67,27 +68,55 @@ export function coerceValue(value: string, schema: JSONSchema): JSONValue { case 'boolean': return value === 'true' || value === '1'; case 'object': - case 'array': + case 'array': { + let jsonValue = value; + let filePath: string | undefined; + + if (value.startsWith('@')) { + filePath = value.slice(1); + if (!filePath) { + throw new Error('Expected a file path after "@" for JSON input'); + } + + try { + jsonValue = readFileSync(filePath, 'utf8'); + } catch (err) { + const reason = err instanceof Error ? err.message : String(err); + throw new Error(\`Unable to read JSON input file "\${filePath}": \${reason}\`); + } + } + try { - const parsed = JSON.parse(value); + const parsed = JSON.parse(jsonValue); + const inputDescription = filePath ? \`file "\${filePath}"\` : value; if (type === 'array') { if (!Array.isArray(parsed)) { - throw new Error(`Expected JSON array for schema type "array", got: ${value}`); - } - } else { - if (parsed === null || Array.isArray(parsed) || typeof parsed !== 'object') { - throw new Error(`Expected JSON object for schema type "object", got: ${value}`); + throw new Error( + \`Expected JSON array for schema type "array", got: \${inputDescription}\`, + ); } + } else if ( + parsed === null || + Array.isArray(parsed) || + typeof parsed !== 'object' + ) { + throw new Error( + \`Expected JSON object for schema type "object", got: \${inputDescription}\`, + ); } return parsed as JSONValue; } catch (err) { if (err instanceof SyntaxError) { - throw new Error(`Expected valid JSON, got: ${value}`); + if (filePath) { + throw new Error(\`Expected valid JSON in file "\${filePath}"\`); + } + throw new Error(\`Expected valid JSON, got: \${value}\`); } throw err; } + } default: return value; } From 217c6a365ab6706b8ad4bd0bcbfd3313ea42b20c Mon Sep 17 00:00:00 2001 From: Muhammad Bin Zohaib Date: Wed, 18 Nov 2026 20:09:10 +0500 Subject: [PATCH 2/5] test: cover JSON file inputs --- test/commands.spec.ts | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/commands.spec.ts b/test/commands.spec.ts index afa37a6..667dc4f 100644 --- a/test/commands.spec.ts +++ b/test/commands.spec.ts @@ -1,3 +1,6 @@ +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; import { describe, expect, it, beforeEach, afterEach, jest } from '@jest/globals'; import { Command, Option } from 'commander'; import { deriveActionName, coerceValue, buildCommands, deriveSelfIdentifier } from '../src/commands.js'; @@ -106,6 +109,60 @@ describe('CLI: coerceValue', () => { }); }); +describe('CLI: coerceValue JSON files', () => { + it('should read object and array values from @-prefixed files', () => { + const directory = mkdtempSync(join(tmpdir(), 'make-cli-json-')); + const objectPath = join(directory, 'scenario blueprint.json'); + const arrayPath = join(directory, 'modules.json'); + + try { + writeFileSync(objectPath, '{"name":"My Scenario","flow":[]}', 'utf8'); + writeFileSync(arrayPath, '[1,2,3]', 'utf8'); + + expect(coerceValue(\`@\${objectPath}\`, { type: 'object' })).toEqual({ + name: 'My Scenario', + flow: [], + }); + expect(coerceValue(\`@\${arrayPath}\`, { type: 'array' })).toEqual([1, 2, 3]); + } finally { + rmSync(directory, { recursive: true, force: true }); + } + }); + + it('should report when a JSON input file cannot be read', () => { + const directory = mkdtempSync(join(tmpdir(), 'make-cli-json-')); + const filePath = join(directory, 'missing.json'); + + try { + expect(() => coerceValue(\`@\${filePath}\`, { type: 'object' })).toThrow( + \`Unable to read JSON input file "\${filePath}"\`, + ); + } finally { + rmSync(directory, { recursive: true, force: true }); + } + }); + + it('should report invalid JSON in a file', () => { + const directory = mkdtempSync(join(tmpdir(), 'make-cli-json-')); + const filePath = join(directory, 'invalid.json'); + + try { + writeFileSync(filePath, '{invalid json', 'utf8'); + expect(() => coerceValue(\`@\${filePath}\`, { type: 'object' })).toThrow( + \`Expected valid JSON in file "\${filePath}"\`, + ); + } finally { + rmSync(directory, { recursive: true, force: true }); + } + }); + + it('should require a path after the @ prefix', () => { + expect(() => coerceValue('@', { type: 'object' })).toThrow( + 'Expected a file path after "@" for JSON input', + ); + }); +}); + describe('CLI: resolveAuth', () => { beforeEach(() => { delete process.env.MAKE_API_KEY; From 38ef70d998e1130f79fbb4f43f24b13c310011e0 Mon Sep 17 00:00:00 2001 From: Muhammad Bin Zohaib Date: Wed, 18 Nov 2026 20:09:13 +0500 Subject: [PATCH 3/5] docs: document JSON file inputs --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 796e396..2d01019 100644 --- a/README.md +++ b/README.md @@ -130,10 +130,22 @@ make-cli scenarios create \ --scheduling='{"type":"on-demand"}' \ --blueprint='{"name":"My Scenario","flow":[],"metadata":{}}' +# Create a scenario using a blueprint stored in a file +make-cli scenarios create --team-id=123 --scheduling='{"type":"on-demand"}' --blueprint=@./scenario-blueprint.json + # Output formatting make-cli scenarios list --team-id=123 --output=table ``` +### JSON inputs from files + +Options whose schema expects a JSON object or array accept either inline JSON or a file reference. Prefix the file path with `@`. The path is resolved from the command's current working directory. This is useful for large scenario blueprints and avoids command-line length limits on Windows. + +```bash +make-cli scenarios create --team-id=123 --blueprint=@./scenario-blueprint.json +make-cli scenarios update 456 --blueprint="@./scenario blueprints/production.json" +``` + ### Resource IDs Resource-level actions (`get`, `update`, `delete`, and similar) accept the resource's own ID as a **positional argument**. The long-form flag is still available for scripting or when you prefer being explicit — both forms are equivalent: From 717934993f48817f8cb49a892eeba70be27a0c31 Mon Sep 17 00:00:00 2001 From: Muhammad Bin Zohaib Date: Wed, 18 Nov 2026 20:10:40 +0500 Subject: [PATCH 4/5] fix: correct template string syntax in JSON file errors --- src/commands.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 3fbfe8e..70db386 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -82,18 +82,18 @@ export function coerceValue(value: string, schema: JSONSchema): JSONValue { jsonValue = readFileSync(filePath, 'utf8'); } catch (err) { const reason = err instanceof Error ? err.message : String(err); - throw new Error(\`Unable to read JSON input file "\${filePath}": \${reason}\`); + throw new Error(`Unable to read JSON input file "${filePath}": ${reason}`); } } try { const parsed = JSON.parse(jsonValue); - const inputDescription = filePath ? \`file "\${filePath}"\` : value; + const inputDescription = filePath ? `file "${filePath}"` : value; if (type === 'array') { if (!Array.isArray(parsed)) { throw new Error( - \`Expected JSON array for schema type "array", got: \${inputDescription}\`, + `Expected JSON array for schema type "array", got: ${inputDescription}`, ); } } else if ( @@ -102,7 +102,7 @@ export function coerceValue(value: string, schema: JSONSchema): JSONValue { typeof parsed !== 'object' ) { throw new Error( - \`Expected JSON object for schema type "object", got: \${inputDescription}\`, + `Expected JSON object for schema type "object", got: ${inputDescription}`, ); } @@ -110,9 +110,9 @@ export function coerceValue(value: string, schema: JSONSchema): JSONValue { } catch (err) { if (err instanceof SyntaxError) { if (filePath) { - throw new Error(\`Expected valid JSON in file "\${filePath}"\`); + throw new Error(`Expected valid JSON in file "${filePath}"`); } - throw new Error(\`Expected valid JSON, got: \${value}\`); + throw new Error(`Expected valid JSON, got: ${value}`); } throw err; } From 994944d03ec9201b159186a7d17f039b659a7bd6 Mon Sep 17 00:00:00 2001 From: Muhammad Bin Zohaib Date: Wed, 18 Nov 2026 20:10:43 +0500 Subject: [PATCH 5/5] test: fix template strings in JSON file cases --- test/commands.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/commands.spec.ts b/test/commands.spec.ts index 667dc4f..dc09162 100644 --- a/test/commands.spec.ts +++ b/test/commands.spec.ts @@ -119,11 +119,11 @@ describe('CLI: coerceValue JSON files', () => { writeFileSync(objectPath, '{"name":"My Scenario","flow":[]}', 'utf8'); writeFileSync(arrayPath, '[1,2,3]', 'utf8'); - expect(coerceValue(\`@\${objectPath}\`, { type: 'object' })).toEqual({ + expect(coerceValue(`@${objectPath}`, { type: 'object' })).toEqual({ name: 'My Scenario', flow: [], }); - expect(coerceValue(\`@\${arrayPath}\`, { type: 'array' })).toEqual([1, 2, 3]); + expect(coerceValue(`@${arrayPath}`, { type: 'array' })).toEqual([1, 2, 3]); } finally { rmSync(directory, { recursive: true, force: true }); } @@ -134,8 +134,8 @@ describe('CLI: coerceValue JSON files', () => { const filePath = join(directory, 'missing.json'); try { - expect(() => coerceValue(\`@\${filePath}\`, { type: 'object' })).toThrow( - \`Unable to read JSON input file "\${filePath}"\`, + expect(() => coerceValue(`@${filePath}`, { type: 'object' })).toThrow( + `Unable to read JSON input file "${filePath}"`, ); } finally { rmSync(directory, { recursive: true, force: true }); @@ -148,8 +148,8 @@ describe('CLI: coerceValue JSON files', () => { try { writeFileSync(filePath, '{invalid json', 'utf8'); - expect(() => coerceValue(\`@\${filePath}\`, { type: 'object' })).toThrow( - \`Expected valid JSON in file "\${filePath}"\`, + expect(() => coerceValue(`@${filePath}`, { type: 'object' })).toThrow( + `Expected valid JSON in file "${filePath}"`, ); } finally { rmSync(directory, { recursive: true, force: true });