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
15 changes: 14 additions & 1 deletion bin/confluence.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ function handleCommandError(analytics, commandName, error, onExtra = null) {
process.exit(1);
}

async function readStdin() {
process.stdin.setEncoding('utf8');
let data = '';
for await (const chunk of process.stdin) {
data += chunk;
}
return data;
}

// Wraps a command action with the standard analytics + client + error pipeline.
// The handler still calls analytics.track(name, true) on success so it can opt
// into alternative tracking keys (e.g. *_cancel, *_dry_run).
Expand Down Expand Up @@ -1987,7 +1996,11 @@ program
if (options.inputFile) {
input = fs.readFileSync(options.inputFile, 'utf-8');
} else {
input = fs.readFileSync(process.stdin.fd, 'utf-8');
if (process.stdin.isTTY) {
console.error(chalk.red('Error: No input provided. Use --input-file <path> or pipe content via stdin.'));
process.exit(1);
}
input = await readStdin();
}

const converter = ConfluenceClient.createLocalConverter();
Expand Down
18 changes: 18 additions & 0 deletions tests/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ describe('convert command', () => {
expect(output).toContain('World');
});

test('reads input from stdin when --input-file is omitted', () => {
const output = run(
['convert', '--input-format', 'markdown', '--output-format', 'storage'],
'# Piped\n\nbody\n'
);
expect(output).toContain('<h1>');
expect(output).toContain('Piped');
expect(output).toContain('body');
});

test('handles empty stdin without hanging or crashing', () => {
const output = run(
['convert', '--input-format', 'markdown', '--output-format', 'storage'],
''
);
expect(output).toBe('');
});

test('markdown to storage via files', () => {
const inputFile = writeInput('input.md', '# Test\n\nParagraph\n');
const outputFile = path.join(tmpDir, 'output.xml');
Expand Down