@verbatims/cli 0.1.6 → 0.1.7
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/commands/quotes.ts +48 -1
package/package.json
CHANGED
package/src/commands/quotes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
|
-
import { text, isCancel, cancel, confirm } from '@clack/prompts'
|
|
2
|
+
import { text, isCancel, cancel, confirm, select } from '@clack/prompts'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import { getClient } from '../utils/client.js'
|
|
5
5
|
import { output, type Format } from '../utils/format.js'
|
|
@@ -21,6 +21,7 @@ export function registerQuotesCommand(program: Command) {
|
|
|
21
21
|
.option('--author <id>', 'Filter by author ID')
|
|
22
22
|
.option('--tag <name>', 'Filter by tag')
|
|
23
23
|
.option('--search <q>', 'Search in quote text')
|
|
24
|
+
.option('--status <status>', 'Filter by status (draft|pending|approved|rejected)')
|
|
24
25
|
.option('--sort-by <field>', 'Sort field')
|
|
25
26
|
.option('--sort-order <order>', 'Sort order (asc|desc)')
|
|
26
27
|
.action(async (options: Record<string, string>) => {
|
|
@@ -34,6 +35,7 @@ export function registerQuotesCommand(program: Command) {
|
|
|
34
35
|
author_id: options.author ? Number(options.author) : undefined,
|
|
35
36
|
tag: options.tag,
|
|
36
37
|
search: options.search,
|
|
38
|
+
status: options.status as any,
|
|
37
39
|
sort_by: options.sortBy,
|
|
38
40
|
sort_order: options.sortOrder as 'asc' | 'desc',
|
|
39
41
|
}),
|
|
@@ -121,6 +123,49 @@ export function registerQuotesCommand(program: Command) {
|
|
|
121
123
|
console.log(chalk.green(` Quote #${id} deleted`))
|
|
122
124
|
})
|
|
123
125
|
|
|
126
|
+
quotes
|
|
127
|
+
.command('submit <id>')
|
|
128
|
+
.description('Submit a draft quote for review (draft → pending)')
|
|
129
|
+
.action(async (id: string) => {
|
|
130
|
+
const client = await getClient()
|
|
131
|
+
const format = getFormat(program)
|
|
132
|
+
const { data } = await withSpinner('Submitting quote', () => client.quotes.submit(Number(id)), format)
|
|
133
|
+
console.log(chalk.green(' Quote submitted for review'))
|
|
134
|
+
output(data, format)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
quotes
|
|
138
|
+
.command('moderate <id>')
|
|
139
|
+
.description('Moderate a pending quote (pending → approved|rejected)')
|
|
140
|
+
.option('--action <action>', 'Action to take: approve or reject')
|
|
141
|
+
.option('--reason <reason>', 'Rejection reason (required when rejecting)')
|
|
142
|
+
.action(async (id: string, options: Record<string, string>) => {
|
|
143
|
+
const client = await getClient()
|
|
144
|
+
const format = getFormat(program)
|
|
145
|
+
|
|
146
|
+
const action = options.action ?? await select({
|
|
147
|
+
message: 'Action',
|
|
148
|
+
options: [
|
|
149
|
+
{ value: 'approve', label: 'Approve' },
|
|
150
|
+
{ value: 'reject', label: 'Reject' },
|
|
151
|
+
],
|
|
152
|
+
})
|
|
153
|
+
if (isCancel(action)) cancel('Cancelled')
|
|
154
|
+
|
|
155
|
+
let rejection_reason: string | undefined | null
|
|
156
|
+
if (action === 'reject') {
|
|
157
|
+
rejection_reason = options.reason ?? await text({ message: 'Rejection reason' })
|
|
158
|
+
if (isCancel(rejection_reason)) cancel('Cancelled')
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const { data } = await withSpinner('Moderating quote', () =>
|
|
162
|
+
client.quotes.moderate(Number(id), { action: action as 'approve' | 'reject', rejection_reason }),
|
|
163
|
+
format,
|
|
164
|
+
)
|
|
165
|
+
console.log(chalk.green(` Quote ${action === 'approve' ? 'approved' : 'rejected'}`))
|
|
166
|
+
output(data, format)
|
|
167
|
+
})
|
|
168
|
+
|
|
124
169
|
quotes
|
|
125
170
|
.command('browse')
|
|
126
171
|
.description('Browse quotes interactively')
|
|
@@ -128,6 +173,7 @@ export function registerQuotesCommand(program: Command) {
|
|
|
128
173
|
.option('--author <id>', 'Filter by author ID')
|
|
129
174
|
.option('--tag <name>', 'Filter by tag')
|
|
130
175
|
.option('--search <q>', 'Search in quote text')
|
|
176
|
+
.option('--status <status>', 'Filter by status (draft|pending|approved|rejected)')
|
|
131
177
|
.option('--sort-by <field>', 'Sort field')
|
|
132
178
|
.option('--sort-order <order>', 'Sort order (asc|desc)')
|
|
133
179
|
.action(async (options: Record<string, string>) => {
|
|
@@ -140,6 +186,7 @@ export function registerQuotesCommand(program: Command) {
|
|
|
140
186
|
author_id: options.author ? Number(options.author) : undefined,
|
|
141
187
|
tag: options.tag,
|
|
142
188
|
search: options.search,
|
|
189
|
+
status: options.status as any,
|
|
143
190
|
sort_by: options.sortBy,
|
|
144
191
|
sort_order: options.sortOrder as 'asc' | 'desc',
|
|
145
192
|
}),
|