@autocodeflow/cli 1.5.2 → 1.6.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.
@@ -0,0 +1,79 @@
1
+ import { Command } from 'commander';
2
+ import Table from 'cli-table3';
3
+ import chalk from 'chalk';
4
+ import ora from 'ora';
5
+ import { get, formatApiError } from '../client.js';
6
+ export function sopCommand() {
7
+ const cmd = new Command('sop').description('Inspect SOP definitions');
8
+ // acf sop list
9
+ cmd.command('list')
10
+ .description('List SOP definitions (newest update first)')
11
+ .option('--status <status>', 'Filter by SOP status (draft | published | deprecated)')
12
+ .option('-p, --page <n>', 'Page number', '1')
13
+ .option('-n, --page-size <n>', 'Page size (max 100)', '20')
14
+ .action(async (opts) => {
15
+ const spinner = ora('Fetching SOPs…').start();
16
+ try {
17
+ const data = await get('/sop', {
18
+ page: opts.page,
19
+ pageSize: opts.pageSize,
20
+ status: opts.status,
21
+ });
22
+ spinner.stop();
23
+ const items = data.items ?? [];
24
+ const table = new Table({
25
+ head: ['Title', 'Slug', 'Status', 'Version', 'Updated'],
26
+ colWidths: [32, 24, 12, 12, 24],
27
+ style: { head: ['cyan'] },
28
+ });
29
+ for (const s of items) {
30
+ table.push([
31
+ s.title,
32
+ s.slug,
33
+ statusColor(s.status),
34
+ s.currentVersion ?? '-',
35
+ s.updatedAt ? new Date(s.updatedAt).toLocaleString() : '-',
36
+ ]);
37
+ }
38
+ console.log(table.toString());
39
+ console.log(chalk.gray(`Total: ${data.total ?? items.length} page ${opts.page}`));
40
+ }
41
+ catch (e) {
42
+ spinner.fail('Failed to list SOPs');
43
+ console.error(chalk.red(formatApiError(e)));
44
+ process.exit(1);
45
+ }
46
+ });
47
+ // acf sop show <id>
48
+ cmd.command('show <sopId>')
49
+ .description('Show one SOP: status, current version and markdown body')
50
+ .action(async (sopId) => {
51
+ const spinner = ora('Fetching SOP…').start();
52
+ try {
53
+ const s = await get(`/sop/${sopId}`);
54
+ spinner.stop();
55
+ console.log(chalk.bold(s.title));
56
+ console.log(chalk.gray(`slug: ${s.slug} status: ${s.status} version: ${s.currentVersion ?? '-'} updated: ${s.updatedAt ?? '-'}`));
57
+ if (s.bodyMarkdown) {
58
+ console.log('');
59
+ console.log(s.bodyMarkdown);
60
+ }
61
+ else {
62
+ console.log(chalk.gray('(no body — the SOP has no published version yet)'));
63
+ }
64
+ }
65
+ catch (e) {
66
+ spinner.fail('Failed to show SOP');
67
+ console.error(chalk.red(formatApiError(e)));
68
+ process.exit(1);
69
+ }
70
+ });
71
+ return cmd;
72
+ }
73
+ function statusColor(s) {
74
+ if (s === 'published')
75
+ return chalk.green(s);
76
+ if (s === 'deprecated')
77
+ return chalk.red(s);
78
+ return s;
79
+ }