@newpeak/barista-cli 0.1.7 → 0.1.8
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/dist/commands/liberica/calendar/index.d.ts +3 -0
- package/dist/commands/liberica/calendar/index.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/index.js +11 -0
- package/dist/commands/liberica/calendar/index.js.map +1 -0
- package/dist/commands/liberica/calendar/list.d.ts +3 -0
- package/dist/commands/liberica/calendar/list.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/list.js +181 -0
- package/dist/commands/liberica/calendar/list.js.map +1 -0
- package/dist/commands/liberica/calendar/set.d.ts +3 -0
- package/dist/commands/liberica/calendar/set.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/set.js +120 -0
- package/dist/commands/liberica/calendar/set.js.map +1 -0
- package/dist/commands/liberica/client-contacts/create.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/create.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/create.js +132 -0
- package/dist/commands/liberica/client-contacts/create.js.map +1 -0
- package/dist/commands/liberica/client-contacts/delete.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/delete.js +139 -0
- package/dist/commands/liberica/client-contacts/delete.js.map +1 -0
- package/dist/commands/liberica/client-contacts/get.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/get.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/get.js +92 -0
- package/dist/commands/liberica/client-contacts/get.js.map +1 -0
- package/dist/commands/liberica/client-contacts/index.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/index.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/index.js +17 -0
- package/dist/commands/liberica/client-contacts/index.js.map +1 -0
- package/dist/commands/liberica/client-contacts/list.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/list.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/list.js +92 -0
- package/dist/commands/liberica/client-contacts/list.js.map +1 -0
- package/dist/commands/liberica/client-contacts/update.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/update.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/update.js +156 -0
- package/dist/commands/liberica/client-contacts/update.js.map +1 -0
- package/dist/commands/liberica/dict-types/get.d.ts +3 -0
- package/dist/commands/liberica/dict-types/get.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/get.js +62 -0
- package/dist/commands/liberica/dict-types/get.js.map +1 -0
- package/dist/commands/liberica/dict-types/index.d.ts +3 -0
- package/dist/commands/liberica/dict-types/index.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/index.js +13 -0
- package/dist/commands/liberica/dict-types/index.js.map +1 -0
- package/dist/commands/liberica/dict-types/list.d.ts +3 -0
- package/dist/commands/liberica/dict-types/list.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/list.js +91 -0
- package/dist/commands/liberica/dict-types/list.js.map +1 -0
- package/dist/commands/liberica/dict-types/update.d.ts +3 -0
- package/dist/commands/liberica/dict-types/update.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/update.js +127 -0
- package/dist/commands/liberica/dict-types/update.js.map +1 -0
- package/dist/commands/liberica/dicts/create.d.ts +3 -0
- package/dist/commands/liberica/dicts/create.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/create.js +157 -0
- package/dist/commands/liberica/dicts/create.js.map +1 -0
- package/dist/commands/liberica/dicts/delete.d.ts +3 -0
- package/dist/commands/liberica/dicts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/delete.js +106 -0
- package/dist/commands/liberica/dicts/delete.js.map +1 -0
- package/dist/commands/liberica/dicts/get.d.ts +3 -0
- package/dist/commands/liberica/dicts/get.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/get.js +69 -0
- package/dist/commands/liberica/dicts/get.js.map +1 -0
- package/dist/commands/liberica/dicts/index.d.ts +3 -0
- package/dist/commands/liberica/dicts/index.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/index.js +17 -0
- package/dist/commands/liberica/dicts/index.js.map +1 -0
- package/dist/commands/liberica/dicts/list.d.ts +3 -0
- package/dist/commands/liberica/dicts/list.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/list.js +88 -0
- package/dist/commands/liberica/dicts/list.js.map +1 -0
- package/dist/commands/liberica/dicts/update.d.ts +3 -0
- package/dist/commands/liberica/dicts/update.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/update.js +112 -0
- package/dist/commands/liberica/dicts/update.js.map +1 -0
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +18 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/commands/liberica/operations/active.d.ts +3 -0
- package/dist/commands/liberica/operations/active.d.ts.map +1 -0
- package/dist/commands/liberica/operations/active.js +152 -0
- package/dist/commands/liberica/operations/active.js.map +1 -0
- package/dist/commands/liberica/operations/batch-delete.d.ts +3 -0
- package/dist/commands/liberica/operations/batch-delete.d.ts.map +1 -0
- package/dist/commands/liberica/operations/batch-delete.js +130 -0
- package/dist/commands/liberica/operations/batch-delete.js.map +1 -0
- package/dist/commands/liberica/operations/copy.d.ts +3 -0
- package/dist/commands/liberica/operations/copy.d.ts.map +1 -0
- package/dist/commands/liberica/operations/copy.js +137 -0
- package/dist/commands/liberica/operations/copy.js.map +1 -0
- package/dist/commands/liberica/operations/create.d.ts +3 -0
- package/dist/commands/liberica/operations/create.d.ts.map +1 -0
- package/dist/commands/liberica/operations/create.js +212 -0
- package/dist/commands/liberica/operations/create.js.map +1 -0
- package/dist/commands/liberica/operations/deactive.d.ts +3 -0
- package/dist/commands/liberica/operations/deactive.d.ts.map +1 -0
- package/dist/commands/liberica/operations/deactive.js +152 -0
- package/dist/commands/liberica/operations/deactive.js.map +1 -0
- package/dist/commands/liberica/operations/delete.d.ts +3 -0
- package/dist/commands/liberica/operations/delete.d.ts.map +1 -0
- package/dist/commands/liberica/operations/delete.js +128 -0
- package/dist/commands/liberica/operations/delete.js.map +1 -0
- package/dist/commands/liberica/operations/get.d.ts +3 -0
- package/dist/commands/liberica/operations/get.d.ts.map +1 -0
- package/dist/commands/liberica/operations/get.js +93 -0
- package/dist/commands/liberica/operations/get.js.map +1 -0
- package/dist/commands/liberica/operations/index.d.ts +3 -0
- package/dist/commands/liberica/operations/index.d.ts.map +1 -0
- package/dist/commands/liberica/operations/index.js +25 -0
- package/dist/commands/liberica/operations/index.js.map +1 -0
- package/dist/commands/liberica/operations/list.d.ts +3 -0
- package/dist/commands/liberica/operations/list.d.ts.map +1 -0
- package/dist/commands/liberica/operations/list.js +141 -0
- package/dist/commands/liberica/operations/list.js.map +1 -0
- package/dist/commands/liberica/operations/update.d.ts +3 -0
- package/dist/commands/liberica/operations/update.d.ts.map +1 -0
- package/dist/commands/liberica/operations/update.js +208 -0
- package/dist/commands/liberica/operations/update.js.map +1 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.d.ts +2 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.d.ts.map +1 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.js +41 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.js.map +1 -0
- package/dist/commands/liberica/stock/__tests__/list.test.d.ts +2 -0
- package/dist/commands/liberica/stock/__tests__/list.test.d.ts.map +1 -0
- package/dist/commands/liberica/stock/__tests__/list.test.js +39 -0
- package/dist/commands/liberica/stock/__tests__/list.test.js.map +1 -0
- package/dist/commands/liberica/stock/index.d.ts +3 -0
- package/dist/commands/liberica/stock/index.d.ts.map +1 -0
- package/dist/commands/liberica/stock/index.js +11 -0
- package/dist/commands/liberica/stock/index.js.map +1 -0
- package/dist/commands/liberica/stock/ledger.d.ts +3 -0
- package/dist/commands/liberica/stock/ledger.d.ts.map +1 -0
- package/dist/commands/liberica/stock/ledger.js +154 -0
- package/dist/commands/liberica/stock/ledger.js.map +1 -0
- package/dist/commands/liberica/stock/list.d.ts +3 -0
- package/dist/commands/liberica/stock/list.d.ts.map +1 -0
- package/dist/commands/liberica/stock/list.js +127 -0
- package/dist/commands/liberica/stock/list.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/create.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/create.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/create.js +129 -0
- package/dist/commands/liberica/supplier-contacts/create.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/delete.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/delete.js +88 -0
- package/dist/commands/liberica/supplier-contacts/delete.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/get.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/get.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/get.js +84 -0
- package/dist/commands/liberica/supplier-contacts/get.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/index.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/index.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/index.js +17 -0
- package/dist/commands/liberica/supplier-contacts/index.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/list.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/list.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/list.js +98 -0
- package/dist/commands/liberica/supplier-contacts/list.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/update.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/update.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/update.js +136 -0
- package/dist/commands/liberica/supplier-contacts/update.js.map +1 -0
- package/dist/core/api/client.d.ts +46 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +865 -52
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/calendar.d.ts +28 -0
- package/dist/types/calendar.d.ts.map +1 -0
- package/dist/types/calendar.js +2 -0
- package/dist/types/calendar.js.map +1 -0
- package/dist/types/client-contact.d.ts +65 -0
- package/dist/types/client-contact.d.ts.map +1 -0
- package/dist/types/client-contact.js +4 -0
- package/dist/types/client-contact.js.map +1 -0
- package/dist/types/dict.d.ts +97 -0
- package/dist/types/dict.d.ts.map +1 -0
- package/dist/types/dict.js +2 -0
- package/dist/types/dict.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/operation.d.ts +66 -0
- package/dist/types/operation.d.ts.map +1 -0
- package/dist/types/operation.js +2 -0
- package/dist/types/operation.js.map +1 -0
- package/dist/types/stock.d.ts +133 -0
- package/dist/types/stock.d.ts.map +1 -0
- package/dist/types/stock.js +3 -0
- package/dist/types/stock.js.map +1 -0
- package/dist/types/supplier-contact.d.ts +65 -0
- package/dist/types/supplier-contact.d.ts.map +1 -0
- package/dist/types/supplier-contact.js +4 -0
- package/dist/types/supplier-contact.js.map +1 -0
- package/docs/commands/REFERENCE.md +24 -4
- package/docs/commands/liberica/calendar/DESIGN.md +333 -0
- package/docs/commands/liberica/client-contacts/create.md +152 -0
- package/docs/commands/liberica/client-contacts/delete.md +123 -0
- package/docs/commands/liberica/client-contacts/get.md +133 -0
- package/docs/commands/liberica/client-contacts/list.md +143 -0
- package/docs/commands/liberica/client-contacts/update.md +158 -0
- package/docs/commands/liberica/stock/ledger.md +209 -0
- package/docs/commands/liberica/stock/list.md +165 -0
- package/docs/commands/liberica/supplier-contacts/create.md +152 -0
- package/docs/commands/liberica/supplier-contacts/delete.md +123 -0
- package/docs/commands/liberica/supplier-contacts/get.md +133 -0
- package/docs/commands/liberica/supplier-contacts/list.md +143 -0
- package/docs/commands/liberica/supplier-contacts/update.md +158 -0
- package/package.json +1 -1
- package/src/commands/liberica/calendar/index.ts +13 -0
- package/src/commands/liberica/calendar/list.ts +214 -0
- package/src/commands/liberica/calendar/set.ts +130 -0
- package/src/commands/liberica/client-contacts/create.ts +115 -0
- package/src/commands/liberica/client-contacts/delete.ts +140 -0
- package/src/commands/liberica/client-contacts/get.ts +103 -0
- package/src/commands/liberica/client-contacts/index.ts +19 -0
- package/src/commands/liberica/client-contacts/list.ts +118 -0
- package/src/commands/liberica/client-contacts/update.ts +137 -0
- package/src/commands/liberica/dict-types/get.ts +74 -0
- package/src/commands/liberica/dict-types/index.ts +15 -0
- package/src/commands/liberica/dict-types/list.ts +118 -0
- package/src/commands/liberica/dict-types/update.ts +134 -0
- package/src/commands/liberica/dicts/create.ts +175 -0
- package/src/commands/liberica/dicts/delete.ts +107 -0
- package/src/commands/liberica/dicts/get.ts +80 -0
- package/src/commands/liberica/dicts/index.ts +19 -0
- package/src/commands/liberica/dicts/list.ts +114 -0
- package/src/commands/liberica/dicts/update.ts +116 -0
- package/src/commands/liberica/index.ts +18 -0
- package/src/commands/liberica/operations/active.ts +153 -0
- package/src/commands/liberica/operations/batch-delete.ts +131 -0
- package/src/commands/liberica/operations/copy.ts +138 -0
- package/src/commands/liberica/operations/create.ts +223 -0
- package/src/commands/liberica/operations/deactive.ts +152 -0
- package/src/commands/liberica/operations/delete.ts +128 -0
- package/src/commands/liberica/operations/design.md +587 -0
- package/src/commands/liberica/operations/get.ts +112 -0
- package/src/commands/liberica/operations/index.ts +27 -0
- package/src/commands/liberica/operations/list.ts +180 -0
- package/src/commands/liberica/operations/update.ts +218 -0
- package/src/commands/liberica/stock/index.ts +13 -0
- package/src/commands/liberica/stock/ledger.ts +159 -0
- package/src/commands/liberica/stock/list.ts +128 -0
- package/src/commands/liberica/supplier-contacts/create.ts +120 -0
- package/src/commands/liberica/supplier-contacts/delete.ts +88 -0
- package/src/commands/liberica/supplier-contacts/get.ts +94 -0
- package/src/commands/liberica/supplier-contacts/index.ts +19 -0
- package/src/commands/liberica/supplier-contacts/list.ts +130 -0
- package/src/commands/liberica/supplier-contacts/update.ts +127 -0
- package/src/core/api/client.ts +1093 -74
- package/src/index.ts +1 -1
- package/src/types/calendar.ts +36 -0
- package/src/types/client-contact.ts +78 -0
- package/src/types/dict.ts +121 -0
- package/src/types/index.ts +5 -0
- package/src/types/operation.ts +72 -0
- package/src/types/stock.ts +161 -0
- package/src/types/supplier-contact.ts +78 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { Operation } from '../../../types/operation.js';
|
|
7
|
+
|
|
8
|
+
export function createOperationsCopyCommand(): Command {
|
|
9
|
+
const copyCommand = new Command('copy');
|
|
10
|
+
copyCommand
|
|
11
|
+
.description('Copy an operation')
|
|
12
|
+
.option('--id <id>', 'Source operation ID')
|
|
13
|
+
.option('-n, --name <name>', 'New operation name (optional, defaults to "Copy of {originalName}")')
|
|
14
|
+
.option('--force', 'Skip confirmation and copy directly')
|
|
15
|
+
.option('--dry-run', 'Preview without making API call')
|
|
16
|
+
.option('--json', 'Output as JSON')
|
|
17
|
+
.action(async (options: Record<string, unknown>) => {
|
|
18
|
+
const context = configManager.getCurrentContext();
|
|
19
|
+
const environment = context.environment as Environment;
|
|
20
|
+
const tenant = context.tenant;
|
|
21
|
+
const force = options.force === true;
|
|
22
|
+
const dryRun = options.dryRun === true;
|
|
23
|
+
const jsonOutput = options.json === true;
|
|
24
|
+
const newName = options.name as string | undefined;
|
|
25
|
+
|
|
26
|
+
const operationId = options.id as string | undefined;
|
|
27
|
+
if (!operationId) {
|
|
28
|
+
if (jsonOutput) {
|
|
29
|
+
console.log(JSON.stringify({ success: false, error: { code: 'MISSING_ID', message: '--id is required' } }));
|
|
30
|
+
} else {
|
|
31
|
+
console.error(chalk.red('\n✗ --id is required\n'));
|
|
32
|
+
}
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!jsonOutput) {
|
|
37
|
+
console.log(chalk.bold(`\n📋 Copy Operation (${environment})\n`));
|
|
38
|
+
console.log(chalk.gray(` Source ID: ${operationId}`));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let operation: Operation | undefined;
|
|
42
|
+
try {
|
|
43
|
+
const operationResponse = await apiClient.getOperationDetail(environment, tenant, operationId);
|
|
44
|
+
if (!operationResponse.success || !operationResponse.data || !('operationId' in operationResponse.data)) {
|
|
45
|
+
const errMsg = `Operation not found: ${operationId}`;
|
|
46
|
+
if (jsonOutput) {
|
|
47
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
48
|
+
} else {
|
|
49
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
50
|
+
}
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
operation = operationResponse.data as Operation;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
56
|
+
if (jsonOutput) {
|
|
57
|
+
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch operation: ${errMsg}` } }));
|
|
58
|
+
} else {
|
|
59
|
+
console.error(chalk.red(`\n✗ Failed to fetch operation: ${errMsg}\n`));
|
|
60
|
+
}
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const operationName = newName || `Copy of ${operation.operationName}`;
|
|
65
|
+
|
|
66
|
+
if (!jsonOutput) {
|
|
67
|
+
console.log(chalk.gray(` Source Name: ${operation.operationName}`));
|
|
68
|
+
console.log(chalk.gray(` Source Code: ${operation.operationCode}`));
|
|
69
|
+
console.log(chalk.gray(` Type: ${operation.operationType}`));
|
|
70
|
+
if (operation.workCenterCode) {
|
|
71
|
+
console.log(chalk.gray(` Work Center: ${operation.workCenterCode}`));
|
|
72
|
+
}
|
|
73
|
+
if (operation.leadTime) {
|
|
74
|
+
console.log(chalk.gray(` Lead Time: ${operation.leadTime}h`));
|
|
75
|
+
}
|
|
76
|
+
console.log(chalk.cyan(`\n → New Name: ${operationName}\n`));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (dryRun) {
|
|
80
|
+
if (jsonOutput) {
|
|
81
|
+
console.log(JSON.stringify({ success: true, dryRun: true, sourceOperation: operation, newName: operationName }));
|
|
82
|
+
} else {
|
|
83
|
+
console.log(chalk.cyan('🔍 Dry-Run Mode: No actual copy will be made\n'));
|
|
84
|
+
console.log(chalk.yellow(' To copy, run without --dry-run\n'));
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!force) {
|
|
90
|
+
if (jsonOutput) {
|
|
91
|
+
console.log(JSON.stringify({ success: true, dryRun: true, sourceOperation: operation, newName: operationName }));
|
|
92
|
+
} else {
|
|
93
|
+
console.log(chalk.cyan('🔍 Dry-Run Mode: No actual copy will be made\n'));
|
|
94
|
+
console.log(chalk.yellow(' To copy, add --force flag\n'));
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const response = await apiClient.copyOperation(environment, tenant, operationId);
|
|
101
|
+
|
|
102
|
+
if (response.success && response.data && 'operationId' in response.data) {
|
|
103
|
+
const newOperation = response.data as Operation;
|
|
104
|
+
if (jsonOutput) {
|
|
105
|
+
console.log(JSON.stringify({ success: true, operation: newOperation }));
|
|
106
|
+
} else {
|
|
107
|
+
console.log(chalk.green(`\n✓ Operation copied successfully\n`));
|
|
108
|
+
console.log(chalk.gray(` New ID: ${newOperation.operationId}`));
|
|
109
|
+
console.log(chalk.gray(` New Code: ${newOperation.operationCode}`));
|
|
110
|
+
console.log(chalk.gray(` New Name: ${newOperation.operationName}\n`));
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
114
|
+
const errorCode = response.error?.code || 'COPY_ERROR';
|
|
115
|
+
if (jsonOutput) {
|
|
116
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
117
|
+
} else {
|
|
118
|
+
console.error(chalk.red(`\n✗ Failed to copy operation: ${errorMsg}`));
|
|
119
|
+
if (response.error?.code) {
|
|
120
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
121
|
+
}
|
|
122
|
+
console.error();
|
|
123
|
+
}
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
128
|
+
if (jsonOutput) {
|
|
129
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
130
|
+
} else {
|
|
131
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
132
|
+
}
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return copyCommand;
|
|
138
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
4
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
5
|
+
import { OperationCreateRequest, OperationType, StatusFlag } from '../../../types/operation.js';
|
|
6
|
+
|
|
7
|
+
const TYPE_MAPPING: Record<string, string> = {
|
|
8
|
+
EQUIPMENT: 'EQUIPMENT',
|
|
9
|
+
equipment: 'EQUIPMENT',
|
|
10
|
+
机器: 'EQUIPMENT',
|
|
11
|
+
HUMAN: 'HUMAN',
|
|
12
|
+
human: 'HUMAN',
|
|
13
|
+
手工: 'HUMAN',
|
|
14
|
+
PACKAGE: 'PACKAGE',
|
|
15
|
+
package: 'PACKAGE',
|
|
16
|
+
包装: 'PACKAGE',
|
|
17
|
+
QUALITY_TESTING: 'QUALITY_TESTING',
|
|
18
|
+
quality_testing: 'QUALITY_TESTING',
|
|
19
|
+
qualitytesting: 'QUALITY_TESTING',
|
|
20
|
+
质检: 'QUALITY_TESTING',
|
|
21
|
+
OTHER: 'OTHER',
|
|
22
|
+
other: 'OTHER',
|
|
23
|
+
其它: 'OTHER',
|
|
24
|
+
其他: 'OTHER',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const TYPE_DISPLAY: Record<string, string> = {
|
|
28
|
+
EQUIPMENT: '机器',
|
|
29
|
+
HUMAN: '手工',
|
|
30
|
+
PACKAGE: '包装',
|
|
31
|
+
QUALITY_TESTING: '质检',
|
|
32
|
+
OTHER: '其它',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function normalizeOperationType(input: string): string | null {
|
|
36
|
+
const normalized = input.trim().toUpperCase();
|
|
37
|
+
return TYPE_MAPPING[normalized] || null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function displayType(apiValue: string): string {
|
|
41
|
+
return TYPE_DISPLAY[apiValue] || apiValue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function formatTable(data: OperationCreateRequest): string {
|
|
45
|
+
const lines: string[] = [];
|
|
46
|
+
lines.push(` ${chalk.gray('Code:')} ${data.operationCode}`);
|
|
47
|
+
lines.push(` ${chalk.gray('Name:')} ${data.operationName}`);
|
|
48
|
+
if (data.operationType) {
|
|
49
|
+
lines.push(` ${chalk.gray('Type:')} ${displayType(data.operationType)}`);
|
|
50
|
+
}
|
|
51
|
+
if (data.workCenterCode) lines.push(` ${chalk.gray('Work Center:')} ${data.workCenterCode}`);
|
|
52
|
+
if (data.mouldCode) lines.push(` ${chalk.gray('Mould Code:')} ${data.mouldCode}`);
|
|
53
|
+
if (data.mouldType) lines.push(` ${chalk.gray('Mould Type:')} ${data.mouldType}`);
|
|
54
|
+
if (data.equipmentType) lines.push(` ${chalk.gray('Equipment:')} ${data.equipmentType}`);
|
|
55
|
+
if (data.leadTime !== undefined) lines.push(` ${chalk.gray('Lead Time:')} ${data.leadTime}h`);
|
|
56
|
+
if (data.remark) lines.push(` ${chalk.gray('Remark:')} ${data.remark}`);
|
|
57
|
+
return lines.join('\n');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function createOperationCreateCommand(): Command {
|
|
61
|
+
const cmd = new Command('create');
|
|
62
|
+
cmd.description('Create a new operation');
|
|
63
|
+
|
|
64
|
+
cmd
|
|
65
|
+
.option('-c, --code <code>', 'Operation code (auto-generated if not provided)')
|
|
66
|
+
.option('-n, --name <name>', 'Operation name (required)')
|
|
67
|
+
.option('-t, --type <type>', 'Operation type (required, supports: EQUIPMENT/机器, HUMAN/手工, PACKAGE/包装, QUALITY_TESTING/质检, OTHER/其它)')
|
|
68
|
+
.option('-w, --work-center <code>', 'Work center code')
|
|
69
|
+
.option('--mould-code <code>', 'Mould code')
|
|
70
|
+
.option('--mould-type <type>', 'Mould type')
|
|
71
|
+
.option('--equipment-type <type>', 'Equipment type')
|
|
72
|
+
.option('--lead-time <hours>', 'Lead time in hours', parseInt)
|
|
73
|
+
.option('--remark <text>', 'Remarks')
|
|
74
|
+
.option('--dry-run', 'Preview without making API call')
|
|
75
|
+
.option('--json', 'Output as JSON');
|
|
76
|
+
|
|
77
|
+
cmd.action(async () => {
|
|
78
|
+
const context = configManager.getCurrentContext();
|
|
79
|
+
const opts = cmd.opts();
|
|
80
|
+
|
|
81
|
+
const name = opts.name as string | undefined;
|
|
82
|
+
const typeInput = opts.type as string | undefined;
|
|
83
|
+
const workCenter = opts.workCenter as string | undefined;
|
|
84
|
+
const mouldCode = opts.mouldCode as string | undefined;
|
|
85
|
+
const mouldType = opts.mouldType as string | undefined;
|
|
86
|
+
const equipmentType = opts.equipmentType as string | undefined;
|
|
87
|
+
const leadTime = opts.leadTime as number | undefined;
|
|
88
|
+
const remark = opts.remark as string | undefined;
|
|
89
|
+
const dryRun = opts.dryRun === true;
|
|
90
|
+
const jsonOutput = opts.json === true;
|
|
91
|
+
|
|
92
|
+
if (!name) {
|
|
93
|
+
if (jsonOutput) {
|
|
94
|
+
console.log(JSON.stringify({ success: false, error: { code: 'MISSING_OPTION', message: 'Option --name is required' } }));
|
|
95
|
+
} else {
|
|
96
|
+
console.error(chalk.red('\n✗ Error: --name is required\n'));
|
|
97
|
+
}
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!typeInput) {
|
|
102
|
+
if (jsonOutput) {
|
|
103
|
+
console.log(JSON.stringify({ success: false, error: { code: 'MISSING_OPTION', message: 'Option --type is required' } }));
|
|
104
|
+
} else {
|
|
105
|
+
console.error(chalk.red('\n✗ Error: --type is required\n'));
|
|
106
|
+
}
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const operationType = normalizeOperationType(typeInput);
|
|
111
|
+
if (!operationType) {
|
|
112
|
+
const validTypes = ['EQUIPMENT', '机器', 'HUMAN', '手工', 'PACKAGE', '包装', 'QUALITY_TESTING', '质检', 'OTHER', '其它'];
|
|
113
|
+
if (jsonOutput) {
|
|
114
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_OPTION', message: `Invalid type: ${typeInput}. Valid values: ${validTypes.join(', ')}` } }));
|
|
115
|
+
} else {
|
|
116
|
+
console.error(chalk.red(`\n✗ Invalid operation type: ${typeInput}\n Valid values: ${validTypes.join(', ')}\n`));
|
|
117
|
+
}
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Auto-generate operation code if not provided
|
|
122
|
+
let code = opts.code as string | undefined;
|
|
123
|
+
if (!code) {
|
|
124
|
+
const codeResponse = await apiClient.getOperationCode(context.environment, context.tenant);
|
|
125
|
+
if (codeResponse.success && codeResponse.data) {
|
|
126
|
+
code = codeResponse.data;
|
|
127
|
+
} else {
|
|
128
|
+
const errMsg = codeResponse.error?.message || 'Failed to generate operation code';
|
|
129
|
+
if (jsonOutput) {
|
|
130
|
+
console.log(JSON.stringify({ success: false, error: { code: 'CODE_GENERATION_ERROR', message: errMsg } }));
|
|
131
|
+
} else {
|
|
132
|
+
console.error(chalk.red(`\n✗ Failed to generate operation code: ${errMsg}\n`));
|
|
133
|
+
}
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const data = {
|
|
139
|
+
operationCode: code!,
|
|
140
|
+
operationName: name,
|
|
141
|
+
operationType: operationType as OperationType,
|
|
142
|
+
workCenterCode: workCenter,
|
|
143
|
+
mouldCode: mouldCode,
|
|
144
|
+
mouldType: mouldType,
|
|
145
|
+
equipmentType: equipmentType,
|
|
146
|
+
leadTime: leadTime,
|
|
147
|
+
remark: remark,
|
|
148
|
+
statusFlag: 1 as StatusFlag,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
if (dryRun) {
|
|
152
|
+
if (jsonOutput) {
|
|
153
|
+
console.log(JSON.stringify({ success: true, dryRun: true, data }));
|
|
154
|
+
} else {
|
|
155
|
+
console.log(chalk.bold('\n🔍 Dry-Run Mode: No changes will be made\n'));
|
|
156
|
+
console.log(' Operation to be created:');
|
|
157
|
+
console.log(formatTable(data));
|
|
158
|
+
console.log();
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!jsonOutput) {
|
|
164
|
+
console.log(chalk.bold('\n📝 Creating Operation\n'));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const response = await apiClient.createOperation(context.environment, context.tenant, data);
|
|
168
|
+
|
|
169
|
+
if (!response.success) {
|
|
170
|
+
const errorMsg = response.error?.message || 'Failed to create operation';
|
|
171
|
+
const errorCode = response.error?.code || 'CREATE_OPERATION_ERROR';
|
|
172
|
+
if (jsonOutput) {
|
|
173
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
174
|
+
} else {
|
|
175
|
+
console.error(chalk.red(`\n✗ Failed to create operation: ${errorMsg}`));
|
|
176
|
+
if (response.error?.code) {
|
|
177
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
178
|
+
}
|
|
179
|
+
console.error();
|
|
180
|
+
}
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (response.success) {
|
|
185
|
+
const operation = response.data as {
|
|
186
|
+
operationId?: string;
|
|
187
|
+
operationCode?: string;
|
|
188
|
+
operationName?: string;
|
|
189
|
+
operationType?: string;
|
|
190
|
+
workCenterCode?: string;
|
|
191
|
+
mouldCode?: string;
|
|
192
|
+
mouldType?: string;
|
|
193
|
+
equipmentType?: string;
|
|
194
|
+
leadTime?: number;
|
|
195
|
+
remark?: string;
|
|
196
|
+
statusFlag?: number;
|
|
197
|
+
createTime?: string;
|
|
198
|
+
} | undefined;
|
|
199
|
+
|
|
200
|
+
if (jsonOutput) {
|
|
201
|
+
console.log(JSON.stringify({ success: true, data: operation }));
|
|
202
|
+
} else {
|
|
203
|
+
console.log(chalk.green('✓ Operation created successfully\n'));
|
|
204
|
+
if (operation?.operationId) console.log(` ${chalk.gray('Operation ID:')} ${chalk.green(operation.operationId)}`);
|
|
205
|
+
if (operation?.operationCode) console.log(` ${chalk.gray('Code:')} ${operation.operationCode}`);
|
|
206
|
+
if (operation?.operationName) console.log(` ${chalk.gray('Name:')} ${operation.operationName}`);
|
|
207
|
+
if (operation?.operationType) console.log(` ${chalk.gray('Type:')} ${displayType(operation.operationType)}`);
|
|
208
|
+
if (operation?.workCenterCode) console.log(` ${chalk.gray('Work Center:')} ${operation.workCenterCode}`);
|
|
209
|
+
if (operation?.mouldCode) console.log(` ${chalk.gray('Mould Code:')} ${operation.mouldCode}`);
|
|
210
|
+
if (operation?.mouldType) console.log(` ${chalk.gray('Mould Type:')} ${operation.mouldType}`);
|
|
211
|
+
if (operation?.equipmentType) console.log(` ${chalk.gray('Equipment:')} ${operation.equipmentType}`);
|
|
212
|
+
if (operation?.leadTime !== undefined) console.log(` ${chalk.gray('Lead Time:')} ${operation.leadTime}h`);
|
|
213
|
+
if (operation?.statusFlag !== undefined) {
|
|
214
|
+
const statusText = operation.statusFlag === 1 ? 'Enabled' : 'Disabled';
|
|
215
|
+
console.log(` ${chalk.gray('Status:')} ${chalk.green(statusText)}`);
|
|
216
|
+
}
|
|
217
|
+
console.log();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return cmd;
|
|
223
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { Operation } from '../../../types/operation.js';
|
|
7
|
+
|
|
8
|
+
export function createOperationDeactiveCommand(): Command {
|
|
9
|
+
const deactiveCommand = new Command('deactive');
|
|
10
|
+
deactiveCommand
|
|
11
|
+
.description('Disable (deactivate) operation(s)')
|
|
12
|
+
.argument('[operation-id]', 'Operation ID (mutually exclusive with --ids)')
|
|
13
|
+
.option('--ids <ids>', 'Comma-separated operation IDs for batch operations')
|
|
14
|
+
.option('--force', 'Execute the operation (skip dry-run preview)')
|
|
15
|
+
.option('--dry-run', 'Preview the operation without executing (default)')
|
|
16
|
+
.option('--json', 'Output as JSON')
|
|
17
|
+
.action(async (operationId: string | undefined, options: Record<string, unknown>) => {
|
|
18
|
+
const context = configManager.getCurrentContext();
|
|
19
|
+
const environment = context.environment as Environment;
|
|
20
|
+
const tenant = context.tenant;
|
|
21
|
+
const force = options.force === true;
|
|
22
|
+
const dryRun = !force;
|
|
23
|
+
const jsonOutput = options.json === true;
|
|
24
|
+
|
|
25
|
+
const batchIds = options.ids
|
|
26
|
+
? (options.ids as string).split(',').map((id) => id.trim()).filter((id) => id !== '')
|
|
27
|
+
: [];
|
|
28
|
+
|
|
29
|
+
if (!operationId && batchIds.length === 0) {
|
|
30
|
+
const errMsg = 'Invalid operation ID. Provide <operation-id> or use --ids for batch operations.';
|
|
31
|
+
if (jsonOutput) {
|
|
32
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
|
|
33
|
+
} else {
|
|
34
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const allIds = operationId ? [operationId] : batchIds;
|
|
40
|
+
|
|
41
|
+
if (!jsonOutput) {
|
|
42
|
+
console.log(chalk.bold(`\n↓ Disable Operation(s) (${environment})\n`));
|
|
43
|
+
if (batchIds.length > 0) {
|
|
44
|
+
console.log(chalk.gray(` Operation IDs: ${batchIds.join(', ')}`));
|
|
45
|
+
} else {
|
|
46
|
+
console.log(chalk.gray(` Operation ID: ${operationId}`));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (dryRun) {
|
|
51
|
+
if (jsonOutput) {
|
|
52
|
+
console.log(JSON.stringify({
|
|
53
|
+
success: true,
|
|
54
|
+
dryRun: true,
|
|
55
|
+
operationIds: allIds,
|
|
56
|
+
message: 'No actual API call will be made',
|
|
57
|
+
}));
|
|
58
|
+
} else {
|
|
59
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
|
|
60
|
+
console.log(chalk.gray(` This operation will disable ${allIds.length} operation(s).`));
|
|
61
|
+
console.log(chalk.gray('\n To execute, add --force flag.\n'));
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const operations: Operation[] = [];
|
|
67
|
+
for (const id of allIds) {
|
|
68
|
+
try {
|
|
69
|
+
const response = await apiClient.getOperationDetail(environment, tenant, id);
|
|
70
|
+
if (!response.success || !response.data || !('operationId' in response.data)) {
|
|
71
|
+
const errMsg = `Operation not found: ${id}`;
|
|
72
|
+
if (jsonOutput) {
|
|
73
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
74
|
+
} else {
|
|
75
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
76
|
+
}
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
operations.push(response.data as Operation);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
82
|
+
const jsonErr = { success: false, error: { code: 'FETCH_ERROR', message: 'Failed to fetch operation: ' + errMsg } };
|
|
83
|
+
if (jsonOutput) {
|
|
84
|
+
console.log(JSON.stringify(jsonErr));
|
|
85
|
+
} else {
|
|
86
|
+
console.error(chalk.red(`\n✗ Failed to fetch operation: ${errMsg}\n`));
|
|
87
|
+
}
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const allAlreadyDisabled = operations.every((op) => op.statusFlag === 2);
|
|
93
|
+
if (allAlreadyDisabled) {
|
|
94
|
+
const names = operations.map((op) => `"${op.operationName}"`).join(', ');
|
|
95
|
+
const errMsg = `Operation(s) ${names} ${operations.length === 1 ? 'is' : 'are'} already disabled`;
|
|
96
|
+
if (jsonOutput) {
|
|
97
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_DISABLED', message: errMsg } }));
|
|
98
|
+
} else {
|
|
99
|
+
console.error(chalk.yellow(`\n⚠ ${errMsg}\n`));
|
|
100
|
+
}
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!jsonOutput) {
|
|
105
|
+
if (operations.length === 1) {
|
|
106
|
+
console.log(chalk.gray(` Name: ${operations[0].operationName}`));
|
|
107
|
+
console.log(chalk.gray(` Code: ${operations[0].operationCode}`));
|
|
108
|
+
} else {
|
|
109
|
+
operations.forEach((op, i) => {
|
|
110
|
+
console.log(chalk.gray(` [${i + 1}] ${op.operationName} (${op.operationCode})`));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
console.log();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const response = await apiClient.batchDeActiveOperations(environment, tenant, allIds);
|
|
118
|
+
|
|
119
|
+
if (response.success) {
|
|
120
|
+
if (jsonOutput) {
|
|
121
|
+
console.log(JSON.stringify({ success: true, operationIds: allIds }));
|
|
122
|
+
} else {
|
|
123
|
+
const names = operations.map((op) => op.operationName).join(', ');
|
|
124
|
+
console.log(chalk.green(`\n✓ Operation(s) ${names || allIds.join(', ')} disabled\n`));
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
128
|
+
const errorCode = response.error?.code || 'DEACTIVE_ERROR';
|
|
129
|
+
if (jsonOutput) {
|
|
130
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
131
|
+
} else {
|
|
132
|
+
console.error(chalk.red(`\n✗ Failed to disable operation(s): ${errorMsg}`));
|
|
133
|
+
if (response.error?.code) {
|
|
134
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
135
|
+
}
|
|
136
|
+
console.error();
|
|
137
|
+
}
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
142
|
+
if (jsonOutput) {
|
|
143
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
144
|
+
} else {
|
|
145
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
146
|
+
}
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return deactiveCommand;
|
|
152
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { Operation } from '../../../types/operation.js';
|
|
7
|
+
|
|
8
|
+
export function createOperationsDeleteCommand(): Command {
|
|
9
|
+
const deleteCommand = new Command('delete');
|
|
10
|
+
deleteCommand
|
|
11
|
+
.description('Delete an operation')
|
|
12
|
+
.option('--id <id>', 'Operation ID')
|
|
13
|
+
.option('--force', 'Skip confirmation and delete directly')
|
|
14
|
+
.option('--dry-run', 'Preview without making API call')
|
|
15
|
+
.option('--json', 'Output as JSON')
|
|
16
|
+
.action(async (options: Record<string, unknown>) => {
|
|
17
|
+
const context = configManager.getCurrentContext();
|
|
18
|
+
const environment = context.environment as Environment;
|
|
19
|
+
const tenant = context.tenant;
|
|
20
|
+
const dryRun = options.dryRun === true;
|
|
21
|
+
const jsonOutput = options.json === true;
|
|
22
|
+
|
|
23
|
+
const operationId = options.id as string | undefined;
|
|
24
|
+
if (!operationId) {
|
|
25
|
+
if (jsonOutput) {
|
|
26
|
+
console.log(JSON.stringify({ success: false, error: { code: 'MISSING_ID', message: '--id is required' } }));
|
|
27
|
+
} else {
|
|
28
|
+
console.error(chalk.red('\n✗ --id is required\n'));
|
|
29
|
+
}
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!jsonOutput) {
|
|
34
|
+
console.log(chalk.bold(`\n🗑️ Delete Operation (${environment})\n`));
|
|
35
|
+
console.log(chalk.gray(` Operation ID: ${operationId}`));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let operation: Operation | undefined;
|
|
39
|
+
try {
|
|
40
|
+
const operationResponse = await apiClient.getOperationDetail(environment, tenant, operationId);
|
|
41
|
+
if (!operationResponse.success || !operationResponse.data || !('operationId' in operationResponse.data)) {
|
|
42
|
+
const errMsg = `Operation not found: ${operationId}`;
|
|
43
|
+
if (jsonOutput) {
|
|
44
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
45
|
+
} else {
|
|
46
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
47
|
+
}
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
operation = operationResponse.data as Operation;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
53
|
+
if (jsonOutput) {
|
|
54
|
+
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch operation: ${errMsg}` } }));
|
|
55
|
+
} else {
|
|
56
|
+
console.error(chalk.red(`\n✗ Failed to fetch operation: ${errMsg}\n`));
|
|
57
|
+
}
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!jsonOutput) {
|
|
62
|
+
console.log(chalk.gray(` Name: ${operation.operationName}`));
|
|
63
|
+
console.log(chalk.gray(` Code: ${operation.operationCode}`));
|
|
64
|
+
console.log(chalk.gray(` Type: ${operation.operationType}`));
|
|
65
|
+
if (operation.workCenterCode) {
|
|
66
|
+
console.log(chalk.gray(` Work Center: ${operation.workCenterCode}`));
|
|
67
|
+
}
|
|
68
|
+
if (operation.leadTime) {
|
|
69
|
+
console.log(chalk.gray(` Lead Time: ${operation.leadTime}h`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (dryRun) {
|
|
74
|
+
if (jsonOutput) {
|
|
75
|
+
console.log(JSON.stringify({ success: true, dryRun: true, operation }));
|
|
76
|
+
} else {
|
|
77
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual deletion will be made\n'));
|
|
78
|
+
console.log(chalk.yellow(' To delete, add: --force\n'));
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!options.force) {
|
|
84
|
+
if (jsonOutput) {
|
|
85
|
+
console.log(JSON.stringify({ success: true, dryRun: true, operation }));
|
|
86
|
+
} else {
|
|
87
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual deletion will be made\n'));
|
|
88
|
+
console.log(chalk.yellow(' To delete, add: --force\n'));
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const response = await apiClient.deleteOperation(environment, tenant, operationId);
|
|
95
|
+
|
|
96
|
+
if (response.success) {
|
|
97
|
+
if (jsonOutput) {
|
|
98
|
+
console.log(JSON.stringify({ success: true, operationId, name: operation.operationName }));
|
|
99
|
+
} else {
|
|
100
|
+
console.log(chalk.green(`\n✓ Operation "${operation.operationName}" (ID: ${operationId}) deleted\n`));
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
104
|
+
const errorCode = response.error?.code || 'DELETE_ERROR';
|
|
105
|
+
if (jsonOutput) {
|
|
106
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
107
|
+
} else {
|
|
108
|
+
console.error(chalk.red(`\n✗ Failed to delete operation: ${errorMsg}`));
|
|
109
|
+
if (response.error?.code) {
|
|
110
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
111
|
+
}
|
|
112
|
+
console.error();
|
|
113
|
+
}
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
118
|
+
if (jsonOutput) {
|
|
119
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
120
|
+
} else {
|
|
121
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
122
|
+
}
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return deleteCommand;
|
|
128
|
+
}
|