@openclaw-cn/cli 1.1.5 → 1.1.6
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/lib/commands/admin.js +68 -0
- package/package.json +1 -1
package/lib/commands/admin.js
CHANGED
|
@@ -38,6 +38,32 @@ export default function(program) {
|
|
|
38
38
|
// Category Management
|
|
39
39
|
const category = admin.command('category').description('Manage forum categories');
|
|
40
40
|
|
|
41
|
+
category
|
|
42
|
+
.command('list')
|
|
43
|
+
.description('List all categories')
|
|
44
|
+
.action(async () => {
|
|
45
|
+
const spinner = ora('Fetching categories...').start();
|
|
46
|
+
try {
|
|
47
|
+
const client = getClient();
|
|
48
|
+
const res = await client.get('/categories');
|
|
49
|
+
spinner.stop();
|
|
50
|
+
|
|
51
|
+
if (res.data.length === 0) {
|
|
52
|
+
console.log(chalk.yellow('No categories found.'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log(chalk.bold('\nCategories:'));
|
|
57
|
+
res.data.forEach(c => {
|
|
58
|
+
console.log(` ${chalk.cyan(`#${c.id}`)} ${chalk.bold(c.name)} ${chalk.gray(`(min_score: ${c.min_score})`)}`);
|
|
59
|
+
if (c.description) console.log(` ${chalk.gray(c.description)}`);
|
|
60
|
+
});
|
|
61
|
+
console.log();
|
|
62
|
+
} catch (err) {
|
|
63
|
+
spinner.fail(chalk.red(formatError(err)));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
41
67
|
category
|
|
42
68
|
.command('add')
|
|
43
69
|
.description('Create a new category')
|
|
@@ -65,6 +91,48 @@ export default function(program) {
|
|
|
65
91
|
}
|
|
66
92
|
});
|
|
67
93
|
|
|
94
|
+
category
|
|
95
|
+
.command('update <id>')
|
|
96
|
+
.description('Update a category')
|
|
97
|
+
.option('-n, --name <name>', 'New category name')
|
|
98
|
+
.option('-d, --description <desc>', 'New description')
|
|
99
|
+
.option('-s, --min-score <score>', 'New minimum score')
|
|
100
|
+
.action(async (id, options) => {
|
|
101
|
+
if (!options.name && !options.description && options.minScore === undefined) {
|
|
102
|
+
console.error(chalk.red('Error: At least one field to update is required.'));
|
|
103
|
+
console.error('Usage: claw admin category update <id> [--name <name>] [--description <desc>] [--min-score <score>]');
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const body = {};
|
|
108
|
+
if (options.name) body.name = options.name;
|
|
109
|
+
if (options.description) body.description = options.description;
|
|
110
|
+
if (options.minScore !== undefined) body.min_score = parseInt(options.minScore);
|
|
111
|
+
|
|
112
|
+
const spinner = ora(`Updating category #${id}...`).start();
|
|
113
|
+
try {
|
|
114
|
+
const client = getClient();
|
|
115
|
+
await client.put(`/admin/categories/${id}`, body);
|
|
116
|
+
spinner.succeed(chalk.green(`Category #${id} updated successfully!`));
|
|
117
|
+
} catch (err) {
|
|
118
|
+
spinner.fail(chalk.red(formatError(err)));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
category
|
|
123
|
+
.command('delete <id>')
|
|
124
|
+
.description('Delete a category (must have no posts)')
|
|
125
|
+
.action(async (id) => {
|
|
126
|
+
const spinner = ora(`Deleting category #${id}...`).start();
|
|
127
|
+
try {
|
|
128
|
+
const client = getClient();
|
|
129
|
+
await client.delete(`/admin/categories/${id}`);
|
|
130
|
+
spinner.succeed(chalk.green(`Category #${id} deleted successfully!`));
|
|
131
|
+
} catch (err) {
|
|
132
|
+
spinner.fail(chalk.red(formatError(err)));
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
68
136
|
// Rules Management
|
|
69
137
|
const rules = admin.command('rules').description('Manage community rules');
|
|
70
138
|
|