@chabokan.net/cli 0.8.10 → 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.
@@ -2,7 +2,7 @@ import { Flags } from '@oclif/core';
2
2
  import inquirer from 'inquirer';
3
3
  import axios from "axios";
4
4
  import chalk from "chalk";
5
- import { isObject } from "../helper.js";
5
+ import { isObject, handleApiError, logErrorDetails } from "../helper.js";
6
6
  import Command from "../base.js";
7
7
  export default class Login extends Command {
8
8
  static description = 'login to hub.chabokan.net account';
@@ -13,20 +13,23 @@ export default class Login extends Command {
13
13
  token: Flags.string({ char: 't', description: 'login with api token' }),
14
14
  };
15
15
  async run() {
16
- const { args, flags } = await this.parse(Login);
16
+ const { flags } = await this.parse(Login);
17
17
  const cli = this;
18
18
  await this.init_run();
19
19
  const config_json = await this.read_config();
20
- const body = { username: flags.username, password: flags.password };
20
+ const body = {
21
+ username: flags.username,
22
+ password: flags.password
23
+ };
21
24
  if (!flags.token) {
22
25
  if (!flags.username) {
23
- let { username } = await inquirer.prompt({
26
+ const { username } = await inquirer.prompt({
24
27
  type: 'input',
25
28
  message: 'Enter your username:',
26
29
  name: 'username',
27
30
  validate(input) {
28
31
  if (input.length === 0) {
29
- return false;
32
+ return 'Username cannot be empty';
30
33
  }
31
34
  return true;
32
35
  }
@@ -34,57 +37,74 @@ export default class Login extends Command {
34
37
  body.username = username;
35
38
  }
36
39
  if (!flags.password) {
37
- let { password } = await inquirer.prompt({
40
+ const { password } = await inquirer.prompt({
38
41
  type: 'password',
39
42
  name: 'password',
40
43
  message: 'Enter your password:',
41
44
  validate(input) {
42
45
  if (input.length === 0) {
43
- return false;
46
+ return 'Password cannot be empty';
44
47
  }
45
48
  return true;
46
49
  }
47
50
  });
48
51
  body.password = password;
49
52
  }
50
- const { data } = await axios.post("accounts/login/", body, this.axiosConfig);
51
- if (data.success) {
52
- if (!isObject(config_json.users)) {
53
- config_json.users = {};
53
+ if (!body.username || !body.password) {
54
+ cli.log(`${chalk.red('[Error]')} Username and password are required!`);
55
+ return;
56
+ }
57
+ try {
58
+ const { data } = await axios.post("accounts/login/", body, this.axiosConfig);
59
+ if (data.success && data.token) {
60
+ if (!isObject(config_json.users)) {
61
+ config_json.users = {};
62
+ }
63
+ config_json.users[body.username] = {
64
+ token: data.token
65
+ };
66
+ config_json.default_user = body.username;
67
+ await this.write_config(config_json);
68
+ cli.log(`${chalk.green('[Success]')} You are logged in successfully as '${body.username}'.`);
69
+ }
70
+ else {
71
+ cli.log(`${chalk.red('[Error]')} Login failed: Invalid username or password. Please check your credentials and try again.`);
54
72
  }
55
- // @ts-ignore
56
- config_json.users[body.username] = {
57
- "token": data.token
58
- };
59
- config_json["default_user"] = body.username;
60
- this.write_config(config_json);
61
- cli.log(`${chalk.green('[Success]')} you are logged in successfully.`);
62
73
  }
63
- else {
64
- cli.log(`${chalk.red('[Error]')} your username or password is wrong!`);
74
+ catch (error) {
75
+ const errorInfo = handleApiError(error, 'Login failed. Please check your credentials and try again.', {
76
+ endpoint: 'accounts/login/',
77
+ operation: 'Login'
78
+ });
79
+ cli.log(`${chalk.red('[Error]')} ${errorInfo.message}`);
80
+ logErrorDetails(errorInfo, cli);
65
81
  }
66
82
  }
67
83
  else {
68
84
  try {
85
+ if (!this.axiosConfig.headers) {
86
+ this.axiosConfig.headers = {};
87
+ }
69
88
  this.axiosConfig.headers.Authorization = `Token ${flags.token}`;
70
89
  const { data } = await axios.get("accounts/info/", this.axiosConfig);
71
90
  if (!isObject(config_json.users)) {
72
91
  config_json.users = {};
73
92
  }
74
- // @ts-ignore
75
- config_json.users[data.user.email] = {
76
- "token": flags.token
93
+ const email = data.user.email;
94
+ config_json.users[email] = {
95
+ token: flags.token
77
96
  };
78
- config_json["default_user"] = data.user.email;
97
+ config_json.default_user = email;
79
98
  await this.write_config(config_json);
80
- cli.log(`${chalk.green('[Success]')} you are logged in successfully.`);
99
+ cli.log(`${chalk.green('[Success]')} You are logged in successfully as '${email}' using API token.`);
81
100
  }
82
- catch (e) {
83
- if (process.env.CHABOK_DEBUG == "true") {
84
- // @ts-ignore
85
- cli.log(e);
86
- }
87
- cli.log(`${chalk.red('[Error]')} your token is wrong!`);
101
+ catch (error) {
102
+ const errorInfo = handleApiError(error, 'Invalid API token. Please verify your token and try again.', {
103
+ endpoint: 'accounts/info/',
104
+ operation: 'Token Login'
105
+ });
106
+ cli.log(`${chalk.red('[Error]')} ${errorInfo.message}`);
107
+ logErrorDetails(errorInfo, cli);
88
108
  }
89
109
  }
90
110
  }
@@ -1,32 +1,45 @@
1
1
  import Command from "../../base.js";
2
2
  import { ux } from "@oclif/core";
3
+ import chalk from "chalk";
4
+ import { isEmptyObject, handleApiError, logErrorDetails } from "../../helper.js";
3
5
  export default class ServiceList extends Command {
4
6
  static description = "show account services list";
5
7
  static flags = {
6
8
  ...Command.flags,
7
9
  };
8
10
  async run() {
9
- const { args, flags } = await this.parse(ServiceList);
11
+ const { flags } = await this.parse(ServiceList);
10
12
  const cli = this;
11
- await this.init_run();
12
- const config_json = await this.read_config();
13
- let all_services = await this.get_services();
14
- if (all_services.length > 0) {
15
- const services_data = all_services.map((service) => {
16
- // const shamshiate = shamsi.gregorianToJalali(
17
- // new Date(project.created)
18
- // );
19
- return {
20
- Name: service.name,
21
- };
22
- });
23
- ux.table(services_data, {
24
- Name: {},
25
- }, flags);
13
+ try {
14
+ await this.init_run();
15
+ const config_json = await this.read_config();
16
+ if (isEmptyObject(config_json.users)) {
17
+ cli.log(`${chalk.red('[Error]')} Please login first using 'chabok login'.`);
18
+ return;
19
+ }
20
+ const all_services = await this.get_services();
21
+ if (all_services.length > 0) {
22
+ const services_data = all_services.map((service) => {
23
+ return {
24
+ Name: service.name,
25
+ };
26
+ });
27
+ ux.table(services_data, {
28
+ Name: {},
29
+ }, flags);
30
+ }
31
+ else {
32
+ cli.log(`${chalk.yellow('[Info]')} No services found. Please create a service first.`);
33
+ return;
34
+ }
26
35
  }
27
- else {
28
- cli.log("first you should create service");
29
- return;
36
+ catch (error) {
37
+ const errorInfo = handleApiError(error, 'Failed to fetch services list.', {
38
+ endpoint: 'services/',
39
+ operation: 'List Services'
40
+ });
41
+ cli.log(`${chalk.red('[Error]')} ${errorInfo.message}`);
42
+ logErrorDetails(errorInfo, cli);
30
43
  }
31
44
  }
32
45
  }
@@ -6,5 +6,5 @@ export default class ServiceLogs 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: any, selected_service: any): Promise<void>;
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 ServiceLogs extends Command {
11
11
  service: Flags.string({ char: 's', description: 'service name' }),
12
12
  };
13
13
  async run() {
14
- const { args, flags } = await this.parse(ServiceLogs);
14
+ const { flags } = await this.parse(ServiceLogs);
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 ServiceLogs extends Command {
21
21
  return;
22
22
  }
23
23
  if (!flags.service) {
24
- let all_services = await this.get_services();
24
+ const all_services = await this.get_services();
25
25
  if (all_services.length > 0) {
26
- let { service } = await inquirer.prompt({
26
+ const { service } = await inquirer.prompt({
27
27
  type: 'list',
28
28
  message: 'Please select a service:',
29
29
  name: 'service',
@@ -36,24 +36,33 @@ export default class ServiceLogs extends Command {
36
36
  return;
37
37
  }
38
38
  }
39
- await this.send_request(cli, selected_service);
39
+ if (selected_service) {
40
+ await this.send_request(cli, selected_service);
41
+ }
40
42
  }
41
43
  async send_request(cli, selected_service) {
42
44
  try {
43
- if (selected_service) {
44
- const { data } = await axios.get("services/" + selected_service + "/logs/", this.axiosConfig);
45
- if (data.success) {
46
- cli.log(data.logs);
47
- }
45
+ const { data } = await axios.get(`services/${selected_service}/logs/`, this.axiosConfig);
46
+ if (data.success && data.logs) {
47
+ cli.log(data.logs);
48
+ }
49
+ else {
50
+ cli.log(`${chalk.yellow('[Warning]')} No logs available for service '${selected_service}'. The service may not have generated any logs yet.`);
48
51
  }
49
52
  }
50
- catch (e) {
51
- if (e.response.status == 404) {
52
- cli.log(chalk.blue("Selected Service Not Founded."));
53
+ catch (error) {
54
+ const errorInfo = handleApiError(error, 'Failed to fetch service logs.', {
55
+ endpoint: `services/${selected_service}/logs/`,
56
+ serviceName: selected_service,
57
+ operation: 'Fetch Logs'
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.`);
53
61
  }
54
62
  else {
55
- console.log(e.data);
63
+ cli.log(`${chalk.red('[Error]')} ${errorInfo.message}`);
56
64
  }
65
+ logErrorDetails(errorInfo, cli);
57
66
  }
58
67
  }
59
68
  }
@@ -9,5 +9,5 @@ export default class ServiceResize extends Command {
9
9
  help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
10
10
  };
11
11
  run(): Promise<void>;
12
- send_request(cli: any, selected_service: any, ram: any, cpu: any, disk: any): Promise<void>;
12
+ send_request(cli: Command, selected_service: string, ram: string, cpu: string, disk: string): Promise<void>;
13
13
  }
@@ -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 { args, flags } = await this.parse(ServiceResize);
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
- let all_services = await this.get_services({ 'not_status': 'pending', 'has_custom_plan': 'true' });
31
- if (all_services) {
32
- let { service } = await inquirer.prompt({
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
- let { ram } = await inquirer.prompt({
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
- let { cpu } = await inquirer.prompt({
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
- let { disk } = await inquirer.prompt({
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
- if (selected_ram % 0.5 != 0) {
90
- cli.log(`${chalk.red('[Error]')} ram amount should coefficient of 0.5`);
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 (selected_cpu % 0.5 != 0) {
94
- cli.log(`${chalk.red('[Error]')} cpu amount should coefficient of 0.5`);
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 (selected_disk % 5 != 0) {
98
- cli.log(`${chalk.red('[Error]')} disk amount should coefficient of 5`);
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 (selected_service && selected_ram && selected_cpu && selected_disk && !wrong_value) {
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
- if (selected_service) {
108
- const { data } = await axios.post("services/" + selected_service + "/resize/", {
109
- "ram": ram,
110
- "cpu": cpu,
111
- "disk": disk,
112
- }, this.axiosConfig);
113
- if (data.success) {
114
- cli.log(`${chalk.green('[Success]')} service resized successfully.`);
115
- }
116
- else {
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 (e) {
122
- if (e.response.status == 404) {
123
- cli.log(chalk.blue("Selected Service Not Founded."));
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
- console.log(e.data);
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: any, selected_service: any): Promise<void>;
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 { args, flags } = await this.parse(ServiceRestart);
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
- let all_services = await this.get_services({
24
+ const all_services = await this.get_services({
25
25
  not_status: "pending",
26
26
  });
27
- if (all_services) {
28
- let { service } = await inquirer.prompt({
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
- if (selected_service) {
42
- const { data } = await axios.get("services/" + selected_service + "/restart/", this.axiosConfig);
43
- if (data.success) {
44
- cli.log(`${chalk.green("[Success]")} service restarted successfully.`);
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 (e) {
49
- if (e.response.status == 404) {
50
- cli.log(chalk.blue("Selected Service Not Founded."));
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
- console.log(e.data);
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: any, selected_service: any): Promise<void>;
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 { args, flags } = await this.parse(ServiceStart);
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
- let all_services = await this.get_services({ 'not_status': 'pending' });
25
- if (all_services) {
26
- let { service } = await inquirer.prompt({
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
- if (selected_service) {
40
- const { data } = await axios.get("services/" + selected_service + "/start/", this.axiosConfig);
41
- if (data.success) {
42
- cli.log(`${chalk.green('[Success]')} service start successfully.`);
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 (e) {
47
- if (e.response.status == 404) {
48
- cli.log(chalk.blue("Selected Service Not Founded."));
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
- console.log(e.data);
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: any, selected_service: any): Promise<void>;
9
+ send_request(cli: Command, selected_service: string): Promise<void>;
10
10
  }