@aaronshaf/confluence-cli 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/cli/commands/read.ts +53 -0
- package/src/cli/help.ts +24 -0
- package/src/cli/index.ts +17 -0
package/package.json
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { ConfluenceClient } from '../../lib/confluence-client/index.js';
|
|
3
|
+
import { ConfigManager } from '../../lib/config.js';
|
|
4
|
+
import { EXIT_CODES } from '../../lib/errors.js';
|
|
5
|
+
import { escapeXml } from '../../lib/formatters.js';
|
|
6
|
+
import { MarkdownConverter } from '../../lib/markdown/index.js';
|
|
7
|
+
import { resolvePageTarget } from '../../lib/resolve-page-target.js';
|
|
8
|
+
|
|
9
|
+
export interface ReadCommandOptions {
|
|
10
|
+
xml?: boolean;
|
|
11
|
+
html?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function readCommand(target: string, options: ReadCommandOptions = {}): Promise<void> {
|
|
15
|
+
const configManager = new ConfigManager();
|
|
16
|
+
const config = await configManager.getConfig();
|
|
17
|
+
|
|
18
|
+
if (!config) {
|
|
19
|
+
console.error(chalk.red('Not configured. Run: cn setup'));
|
|
20
|
+
process.exit(EXIT_CODES.CONFIG_ERROR);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (options.xml && options.html) {
|
|
24
|
+
console.error(chalk.red('Cannot use --xml and --html together.'));
|
|
25
|
+
process.exit(EXIT_CODES.INVALID_ARGUMENTS);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const pageId = resolvePageTarget(target);
|
|
29
|
+
const client = new ConfluenceClient(config);
|
|
30
|
+
const page = await client.getPage(pageId, true);
|
|
31
|
+
|
|
32
|
+
const storageHtml = page.body?.storage?.value || '';
|
|
33
|
+
|
|
34
|
+
if (options.xml) {
|
|
35
|
+
const converter = new MarkdownConverter();
|
|
36
|
+
const markdown = converter.convert(storageHtml);
|
|
37
|
+
console.log('<page>');
|
|
38
|
+
console.log(` <id>${escapeXml(page.id)}</id>`);
|
|
39
|
+
console.log(` <title>${escapeXml(page.title)}</title>`);
|
|
40
|
+
console.log(` <content>${escapeXml(markdown)}</content>`);
|
|
41
|
+
console.log('</page>');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (options.html) {
|
|
46
|
+
console.log(storageHtml);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const converter = new MarkdownConverter();
|
|
51
|
+
const markdown = converter.convert(storageHtml);
|
|
52
|
+
console.log(markdown);
|
|
53
|
+
}
|
package/src/cli/help.ts
CHANGED
|
@@ -214,6 +214,29 @@ ${chalk.yellow('Options:')}
|
|
|
214
214
|
`);
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
export function showReadHelp(): void {
|
|
218
|
+
console.log(`
|
|
219
|
+
${chalk.bold('cn read - Read and display page content')}
|
|
220
|
+
|
|
221
|
+
${chalk.yellow('Usage:')}
|
|
222
|
+
cn read <id|file> [options]
|
|
223
|
+
|
|
224
|
+
${chalk.yellow('Arguments:')}
|
|
225
|
+
id|file Page ID or path to local .md file
|
|
226
|
+
|
|
227
|
+
${chalk.yellow('Options:')}
|
|
228
|
+
--xml Output in XML format
|
|
229
|
+
--html Output raw Confluence storage format HTML
|
|
230
|
+
--help Show this help message
|
|
231
|
+
|
|
232
|
+
${chalk.yellow('Examples:')}
|
|
233
|
+
cn read 123456 Read page by ID
|
|
234
|
+
cn read ./docs/page.md Read page from local file
|
|
235
|
+
cn read 123456 --xml Read page in XML format
|
|
236
|
+
cn read 123456 --html Read raw HTML storage format
|
|
237
|
+
`);
|
|
238
|
+
}
|
|
239
|
+
|
|
217
240
|
export function showCreateHelp(): void {
|
|
218
241
|
console.log(`
|
|
219
242
|
${chalk.bold('cn create - Create a new Confluence page')}
|
|
@@ -419,6 +442,7 @@ ${chalk.yellow('Commands:')}
|
|
|
419
442
|
cn search Search pages using CQL
|
|
420
443
|
cn spaces List available spaces
|
|
421
444
|
cn info Show page info and labels
|
|
445
|
+
cn read Read and display page content
|
|
422
446
|
cn create Create a new page
|
|
423
447
|
cn update Update an existing page
|
|
424
448
|
cn delete Delete a page
|
package/src/cli/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
showDoctorHelp,
|
|
14
14
|
showHelp,
|
|
15
15
|
showInfoHelp,
|
|
16
|
+
showReadHelp,
|
|
16
17
|
showLabelsHelp,
|
|
17
18
|
showMoveHelp,
|
|
18
19
|
showOpenHelp,
|
|
@@ -37,6 +38,7 @@ import { moveCommand } from './commands/move.js';
|
|
|
37
38
|
import { openCommand } from './commands/open.js';
|
|
38
39
|
import { folderCommand } from './commands/folder.js';
|
|
39
40
|
import { pullCommand } from './commands/pull.js';
|
|
41
|
+
import { readCommand } from './commands/read.js';
|
|
40
42
|
import { searchCommand } from './commands/search.js';
|
|
41
43
|
import { setup } from './commands/setup.js';
|
|
42
44
|
import { spacesCommand } from './commands/spaces.js';
|
|
@@ -276,6 +278,21 @@ async function main(): Promise<void> {
|
|
|
276
278
|
break;
|
|
277
279
|
}
|
|
278
280
|
|
|
281
|
+
case 'read': {
|
|
282
|
+
if (args.includes('--help')) {
|
|
283
|
+
showReadHelp();
|
|
284
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
285
|
+
}
|
|
286
|
+
const target = subArgs.find((arg) => !arg.startsWith('--'));
|
|
287
|
+
if (!target) {
|
|
288
|
+
console.error(chalk.red('Page ID or file path is required.'));
|
|
289
|
+
console.log(chalk.gray('Usage: cn read <id|file>'));
|
|
290
|
+
process.exit(EXIT_CODES.INVALID_ARGUMENTS);
|
|
291
|
+
}
|
|
292
|
+
await readCommand(target, { xml: args.includes('--xml'), html: args.includes('--html') });
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
|
|
279
296
|
case 'create': {
|
|
280
297
|
if (args.includes('--help')) {
|
|
281
298
|
showCreateHelp();
|