@chabokan.net/cli 0.8.9 → 0.8.15
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/README.md +25 -24
- package/dist/base.d.ts +10 -8
- package/dist/base.js +13 -10
- package/dist/commands/account/list.js +24 -15
- package/dist/commands/account/remove.js +12 -8
- package/dist/commands/account/use.js +6 -6
- package/dist/commands/deploy.d.ts +3 -2
- package/dist/commands/deploy.js +115 -70
- package/dist/commands/login.js +51 -31
- package/dist/commands/service/list.js +32 -19
- package/dist/commands/service/logs.d.ts +1 -1
- package/dist/commands/service/logs.js +23 -14
- package/dist/commands/service/resize.d.ts +1 -1
- package/dist/commands/service/resize.js +49 -31
- package/dist/commands/service/restart.d.ts +1 -1
- package/dist/commands/service/restart.js +28 -15
- package/dist/commands/service/start.d.ts +1 -1
- package/dist/commands/service/start.js +28 -15
- package/dist/commands/service/stop.d.ts +1 -1
- package/dist/commands/service/stop.js +28 -15
- package/dist/helper.d.ts +15 -8
- package/dist/helper.js +234 -38
- package/dist/types.d.ts +57 -0
- package/dist/types.js +2 -0
- package/oclif.manifest.json +1 -1
- package/package.json +106 -106
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
2
|
import Command from "../../base.js";
|
|
3
|
-
import { isEmptyObject } from "../../helper.js";
|
|
3
|
+
import { isEmptyObject, handleApiError, logErrorDetails } from "../../helper.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
6
|
import axios from "axios";
|
|
@@ -14,7 +14,7 @@ export default class ServiceResize extends Command {
|
|
|
14
14
|
disk: Flags.string({ char: 'd', description: 'DISK' }),
|
|
15
15
|
};
|
|
16
16
|
async run() {
|
|
17
|
-
const {
|
|
17
|
+
const { flags } = await this.parse(ServiceResize);
|
|
18
18
|
const cli = this;
|
|
19
19
|
await this.init_run();
|
|
20
20
|
const config_json = await this.read_config();
|
|
@@ -27,9 +27,9 @@ export default class ServiceResize extends Command {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
if (!selected_service) {
|
|
30
|
-
|
|
31
|
-
if (all_services) {
|
|
32
|
-
|
|
30
|
+
const all_services = await this.get_services({ 'not_status': 'pending', 'has_custom_plan': 'true' });
|
|
31
|
+
if (all_services && all_services.length > 0) {
|
|
32
|
+
const { service } = await inquirer.prompt({
|
|
33
33
|
type: 'list',
|
|
34
34
|
message: 'Please select a service:',
|
|
35
35
|
name: 'service',
|
|
@@ -37,9 +37,13 @@ export default class ServiceResize extends Command {
|
|
|
37
37
|
});
|
|
38
38
|
selected_service = service;
|
|
39
39
|
}
|
|
40
|
+
else {
|
|
41
|
+
cli.log("No services available for resize.");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
if (!selected_ram) {
|
|
42
|
-
|
|
46
|
+
const { ram } = await inquirer.prompt({
|
|
43
47
|
type: 'list',
|
|
44
48
|
message: 'Please select service ram:',
|
|
45
49
|
name: 'ram',
|
|
@@ -55,7 +59,7 @@ export default class ServiceResize extends Command {
|
|
|
55
59
|
selected_ram = ram;
|
|
56
60
|
}
|
|
57
61
|
if (!selected_cpu) {
|
|
58
|
-
|
|
62
|
+
const { cpu } = await inquirer.prompt({
|
|
59
63
|
type: 'list',
|
|
60
64
|
message: 'Please select service cpu:',
|
|
61
65
|
name: 'cpu',
|
|
@@ -70,7 +74,7 @@ export default class ServiceResize extends Command {
|
|
|
70
74
|
selected_cpu = cpu;
|
|
71
75
|
}
|
|
72
76
|
if (!selected_disk) {
|
|
73
|
-
|
|
77
|
+
const { disk } = await inquirer.prompt({
|
|
74
78
|
type: 'list',
|
|
75
79
|
message: 'Please select service disk:',
|
|
76
80
|
name: 'disk',
|
|
@@ -85,46 +89,60 @@ export default class ServiceResize extends Command {
|
|
|
85
89
|
});
|
|
86
90
|
selected_disk = disk;
|
|
87
91
|
}
|
|
92
|
+
if (!selected_service || !selected_ram || !selected_cpu || !selected_disk) {
|
|
93
|
+
cli.log(`${chalk.red('[Error]')} All parameters are required.`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
88
96
|
let wrong_value = false;
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
const ramNum = parseFloat(selected_ram);
|
|
98
|
+
const cpuNum = parseFloat(selected_cpu);
|
|
99
|
+
const diskNum = parseFloat(selected_disk);
|
|
100
|
+
if (isNaN(ramNum) || ramNum % 0.5 !== 0) {
|
|
101
|
+
cli.log(`${chalk.red('[Error]')} RAM amount should be a multiple of 0.5`);
|
|
91
102
|
wrong_value = true;
|
|
92
103
|
}
|
|
93
|
-
if (
|
|
94
|
-
cli.log(`${chalk.red('[Error]')}
|
|
104
|
+
if (isNaN(cpuNum) || cpuNum % 0.5 !== 0) {
|
|
105
|
+
cli.log(`${chalk.red('[Error]')} CPU amount should be a multiple of 0.5`);
|
|
95
106
|
wrong_value = true;
|
|
96
107
|
}
|
|
97
|
-
if (
|
|
98
|
-
cli.log(`${chalk.red('[Error]')}
|
|
108
|
+
if (isNaN(diskNum) || diskNum % 5 !== 0) {
|
|
109
|
+
cli.log(`${chalk.red('[Error]')} Disk amount should be a multiple of 5`);
|
|
99
110
|
wrong_value = true;
|
|
100
111
|
}
|
|
101
|
-
if (
|
|
112
|
+
if (!wrong_value) {
|
|
102
113
|
await this.send_request(cli, selected_service, selected_ram, selected_cpu, selected_disk);
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
async send_request(cli, selected_service, ram, cpu, disk) {
|
|
106
117
|
try {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
cli.log(`${chalk.red('[Error]')} some problem in resize.`);
|
|
118
|
-
}
|
|
118
|
+
const { data } = await axios.post(`services/${selected_service}/resize/`, {
|
|
119
|
+
ram: ram,
|
|
120
|
+
cpu: cpu,
|
|
121
|
+
disk: disk,
|
|
122
|
+
}, this.axiosConfig);
|
|
123
|
+
if (data.success) {
|
|
124
|
+
cli.log(`${chalk.green('[Success]')} Service '${selected_service}' resized successfully (RAM: ${ram}G, CPU: ${cpu} cores, Disk: ${disk}G).`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
cli.log(`${chalk.red('[Error]')} Failed to resize service '${selected_service}'. ${data.message || 'Please verify the resource values and try again.'}`);
|
|
119
128
|
}
|
|
120
129
|
}
|
|
121
|
-
catch (
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
catch (error) {
|
|
131
|
+
const errorInfo = handleApiError(error, 'Failed to resize service.', {
|
|
132
|
+
endpoint: `services/${selected_service}/resize/`,
|
|
133
|
+
serviceName: selected_service,
|
|
134
|
+
operation: 'Resize Service'
|
|
135
|
+
});
|
|
136
|
+
if (errorInfo.status === 404) {
|
|
137
|
+
cli.log(`${chalk.red('[Error]')} Service '${selected_service}' not found. Please verify the service name using 'chabok service list' and try again.`);
|
|
138
|
+
}
|
|
139
|
+
else if (errorInfo.status === 400 || errorInfo.status === 422) {
|
|
140
|
+
cli.log(`${chalk.red('[Error]')} Invalid resize parameters: ${errorInfo.message}. Please check that RAM is a multiple of 0.5, CPU is a multiple of 0.5, and Disk is a multiple of 5.`);
|
|
124
141
|
}
|
|
125
142
|
else {
|
|
126
|
-
|
|
143
|
+
cli.log(`${chalk.red('[Error]')} ${errorInfo.message}`);
|
|
127
144
|
}
|
|
145
|
+
logErrorDetails(errorInfo, cli);
|
|
128
146
|
}
|
|
129
147
|
}
|
|
130
148
|
}
|
|
@@ -6,5 +6,5 @@ export default class ServiceRestart extends Command {
|
|
|
6
6
|
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
7
7
|
};
|
|
8
8
|
run(): Promise<void>;
|
|
9
|
-
send_request(cli:
|
|
9
|
+
send_request(cli: Command, selected_service: string): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Flags } from "@oclif/core";
|
|
2
2
|
import Command from "../../base.js";
|
|
3
|
-
import { isEmptyObject } from "../../helper.js";
|
|
3
|
+
import { isEmptyObject, handleApiError, logErrorDetails } from "../../helper.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import inquirer from "inquirer";
|
|
6
6
|
import axios from "axios";
|
|
@@ -11,7 +11,7 @@ export default class ServiceRestart extends Command {
|
|
|
11
11
|
service: Flags.string({ char: "s", description: "service name" }),
|
|
12
12
|
};
|
|
13
13
|
async run() {
|
|
14
|
-
const {
|
|
14
|
+
const { flags } = await this.parse(ServiceRestart);
|
|
15
15
|
const cli = this;
|
|
16
16
|
await this.init_run();
|
|
17
17
|
const config_json = await this.read_config();
|
|
@@ -21,11 +21,11 @@ export default class ServiceRestart extends Command {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
if (!flags.service) {
|
|
24
|
-
|
|
24
|
+
const all_services = await this.get_services({
|
|
25
25
|
not_status: "pending",
|
|
26
26
|
});
|
|
27
|
-
if (all_services) {
|
|
28
|
-
|
|
27
|
+
if (all_services && all_services.length > 0) {
|
|
28
|
+
const { service } = await inquirer.prompt({
|
|
29
29
|
type: "list",
|
|
30
30
|
message: "Please select a service:",
|
|
31
31
|
name: "service",
|
|
@@ -33,25 +33,38 @@ export default class ServiceRestart extends Command {
|
|
|
33
33
|
});
|
|
34
34
|
selected_service = service;
|
|
35
35
|
}
|
|
36
|
+
else {
|
|
37
|
+
cli.log("No services available.");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (selected_service) {
|
|
42
|
+
await this.send_request(cli, selected_service);
|
|
36
43
|
}
|
|
37
|
-
await this.send_request(cli, selected_service);
|
|
38
44
|
}
|
|
39
45
|
async send_request(cli, selected_service) {
|
|
40
46
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
const { data } = await axios.get(`services/${selected_service}/restart/`, this.axiosConfig);
|
|
48
|
+
if (data.success) {
|
|
49
|
+
cli.log(`${chalk.green("[Success]")} Service '${selected_service}' restarted successfully.`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
cli.log(`${chalk.red("[Error]")} Failed to restart service '${selected_service}'. ${data.message || 'Please try again later.'}`);
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
|
-
catch (
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
catch (error) {
|
|
56
|
+
const errorInfo = handleApiError(error, 'Failed to restart service.', {
|
|
57
|
+
endpoint: `services/${selected_service}/restart/`,
|
|
58
|
+
serviceName: selected_service,
|
|
59
|
+
operation: 'Restart Service'
|
|
60
|
+
});
|
|
61
|
+
if (errorInfo.status === 404) {
|
|
62
|
+
cli.log(`${chalk.red("[Error]")} Service '${selected_service}' not found. Please verify the service name using 'chabok service list' and try again.`);
|
|
51
63
|
}
|
|
52
64
|
else {
|
|
53
|
-
|
|
65
|
+
cli.log(`${chalk.red("[Error]")} ${errorInfo.message}`);
|
|
54
66
|
}
|
|
67
|
+
logErrorDetails(errorInfo, cli);
|
|
55
68
|
}
|
|
56
69
|
}
|
|
57
70
|
}
|
|
@@ -6,5 +6,5 @@ export default class ServiceStart extends Command {
|
|
|
6
6
|
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
7
7
|
};
|
|
8
8
|
run(): Promise<void>;
|
|
9
|
-
send_request(cli:
|
|
9
|
+
send_request(cli: Command, selected_service: string): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
2
|
import Command from "../../base.js";
|
|
3
|
-
import { isEmptyObject } from "../../helper.js";
|
|
3
|
+
import { isEmptyObject, handleApiError, logErrorDetails } from "../../helper.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
6
|
import axios from "axios";
|
|
@@ -11,7 +11,7 @@ export default class ServiceStart extends Command {
|
|
|
11
11
|
service: Flags.string({ char: 's', description: 'service name' }),
|
|
12
12
|
};
|
|
13
13
|
async run() {
|
|
14
|
-
const {
|
|
14
|
+
const { flags } = await this.parse(ServiceStart);
|
|
15
15
|
const cli = this;
|
|
16
16
|
await this.init_run();
|
|
17
17
|
const config_json = await this.read_config();
|
|
@@ -21,9 +21,9 @@ export default class ServiceStart extends Command {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
if (!flags.service) {
|
|
24
|
-
|
|
25
|
-
if (all_services) {
|
|
26
|
-
|
|
24
|
+
const all_services = await this.get_services({ 'not_status': 'pending' });
|
|
25
|
+
if (all_services && all_services.length > 0) {
|
|
26
|
+
const { service } = await inquirer.prompt({
|
|
27
27
|
type: 'list',
|
|
28
28
|
message: 'Please select a service:',
|
|
29
29
|
name: 'service',
|
|
@@ -31,25 +31,38 @@ export default class ServiceStart extends Command {
|
|
|
31
31
|
});
|
|
32
32
|
selected_service = service;
|
|
33
33
|
}
|
|
34
|
+
else {
|
|
35
|
+
cli.log("No services available.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (selected_service) {
|
|
40
|
+
await this.send_request(cli, selected_service);
|
|
34
41
|
}
|
|
35
|
-
await this.send_request(cli, selected_service);
|
|
36
42
|
}
|
|
37
43
|
async send_request(cli, selected_service) {
|
|
38
44
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const { data } = await axios.get(`services/${selected_service}/start/`, this.axiosConfig);
|
|
46
|
+
if (data.success) {
|
|
47
|
+
cli.log(`${chalk.green('[Success]')} Service '${selected_service}' started successfully.`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
cli.log(`${chalk.red('[Error]')} Failed to start service '${selected_service}'. ${data.message || 'Please check the service status and try again.'}`);
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
|
-
catch (
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
catch (error) {
|
|
54
|
+
const errorInfo = handleApiError(error, 'Failed to start service.', {
|
|
55
|
+
endpoint: `services/${selected_service}/start/`,
|
|
56
|
+
serviceName: selected_service,
|
|
57
|
+
operation: 'Start Service'
|
|
58
|
+
});
|
|
59
|
+
if (errorInfo.status === 404) {
|
|
60
|
+
cli.log(`${chalk.red('[Error]')} Service '${selected_service}' not found. Please verify the service name using 'chabok service list' and try again.`);
|
|
49
61
|
}
|
|
50
62
|
else {
|
|
51
|
-
|
|
63
|
+
cli.log(`${chalk.red('[Error]')} ${errorInfo.message}`);
|
|
52
64
|
}
|
|
65
|
+
logErrorDetails(errorInfo, cli);
|
|
53
66
|
}
|
|
54
67
|
}
|
|
55
68
|
}
|
|
@@ -6,5 +6,5 @@ export default class ServiceStop extends Command {
|
|
|
6
6
|
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
7
7
|
};
|
|
8
8
|
run(): Promise<void>;
|
|
9
|
-
send_request(cli:
|
|
9
|
+
send_request(cli: Command, selected_service: string): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
2
|
import Command from "../../base.js";
|
|
3
|
-
import { isEmptyObject } from "../../helper.js";
|
|
3
|
+
import { isEmptyObject, handleApiError, logErrorDetails } from "../../helper.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
6
|
import axios from "axios";
|
|
@@ -11,7 +11,7 @@ export default class ServiceStop extends Command {
|
|
|
11
11
|
service: Flags.string({ char: 's', description: 'service name' }),
|
|
12
12
|
};
|
|
13
13
|
async run() {
|
|
14
|
-
const {
|
|
14
|
+
const { flags } = await this.parse(ServiceStop);
|
|
15
15
|
const cli = this;
|
|
16
16
|
await this.init_run();
|
|
17
17
|
const config_json = await this.read_config();
|
|
@@ -21,9 +21,9 @@ export default class ServiceStop extends Command {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
if (!flags.service) {
|
|
24
|
-
|
|
25
|
-
if (all_services) {
|
|
26
|
-
|
|
24
|
+
const all_services = await this.get_services({ 'not_status': 'pending' });
|
|
25
|
+
if (all_services && all_services.length > 0) {
|
|
26
|
+
const { service } = await inquirer.prompt({
|
|
27
27
|
type: 'list',
|
|
28
28
|
message: 'Please select a service:',
|
|
29
29
|
name: 'service',
|
|
@@ -31,25 +31,38 @@ export default class ServiceStop extends Command {
|
|
|
31
31
|
});
|
|
32
32
|
selected_service = service;
|
|
33
33
|
}
|
|
34
|
+
else {
|
|
35
|
+
cli.log("No services available.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (selected_service) {
|
|
40
|
+
await this.send_request(cli, selected_service);
|
|
34
41
|
}
|
|
35
|
-
await this.send_request(cli, selected_service);
|
|
36
42
|
}
|
|
37
43
|
async send_request(cli, selected_service) {
|
|
38
44
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const { data } = await axios.get(`services/${selected_service}/stop/`, this.axiosConfig);
|
|
46
|
+
if (data.success) {
|
|
47
|
+
cli.log(`${chalk.green('[Success]')} Service '${selected_service}' stopped successfully.`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
cli.log(`${chalk.red('[Error]')} Failed to stop service '${selected_service}'. ${data.message || 'Please try again later.'}`);
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
|
-
catch (
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
catch (error) {
|
|
54
|
+
const errorInfo = handleApiError(error, 'Failed to stop service.', {
|
|
55
|
+
endpoint: `services/${selected_service}/stop/`,
|
|
56
|
+
serviceName: selected_service,
|
|
57
|
+
operation: 'Stop Service'
|
|
58
|
+
});
|
|
59
|
+
if (errorInfo.status === 404) {
|
|
60
|
+
cli.log(`${chalk.red('[Error]')} Service '${selected_service}' not found. Please verify the service name using 'chabok service list' and try again.`);
|
|
49
61
|
}
|
|
50
62
|
else {
|
|
51
|
-
|
|
63
|
+
cli.log(`${chalk.red('[Error]')} ${errorInfo.message}`);
|
|
52
64
|
}
|
|
65
|
+
logErrorDetails(errorInfo, cli);
|
|
53
66
|
}
|
|
54
67
|
}
|
|
55
68
|
}
|
package/dist/helper.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from "axios";
|
|
1
2
|
import { Ignore } from 'ignore';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export declare function get_all_services(filter: {} | undefined, axiosConfig: any): Promise<any>;
|
|
3
|
+
import type { ConfigFile, Service, ErrorInfo } from './types.js';
|
|
4
|
+
export declare function isObject(obj: unknown): obj is Record<string, unknown>;
|
|
5
|
+
export declare function isEmptyObject(obj: unknown): boolean;
|
|
6
|
+
export declare function read_config_file(): ConfigFile;
|
|
7
|
+
export declare function get_all_services(filter: Record<string, string> | undefined, axiosConfig: AxiosRequestConfig): Promise<Service[]>;
|
|
9
8
|
export declare function trimLines(lines: string[]): string[];
|
|
10
9
|
export declare const loadIgnoreFile: (ignoreInstance: Ignore, ignoreFilePath: string, projectPath: string) => void;
|
|
11
10
|
export declare function addIgnorePatterns(ignoreInstance: Ignore, projectPath: string, dir: string): void;
|
|
12
|
-
export declare const checkUpdate: (version:
|
|
11
|
+
export declare const checkUpdate: (version: string) => Promise<void>;
|
|
12
|
+
export declare function handleApiError(error: unknown, defaultMessage: string, context?: {
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
serviceName?: string;
|
|
15
|
+
operation?: string;
|
|
16
|
+
}): ErrorInfo;
|
|
17
|
+
export declare function logErrorDetails(errorInfo: ErrorInfo, command: {
|
|
18
|
+
log: (msg: string) => void;
|
|
19
|
+
}): void;
|