@boltic/cli 0.0.1
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 +149 -0
- package/api/integration.js +469 -0
- package/api/login.js +50 -0
- package/cli.js +128 -0
- package/commands/integration.js +952 -0
- package/commands/login.js +170 -0
- package/config/environments.js +13 -0
- package/helper/command-suggestions.js +54 -0
- package/helper/env.js +27 -0
- package/helper/error.js +123 -0
- package/helper/folder.js +204 -0
- package/helper/secure-storage.js +74 -0
- package/helper/verbose.js +20 -0
- package/index.js +14 -0
- package/package.json +57 -0
- package/templates/schemas.js +506 -0
- package/utils/integration.js +47 -0
package/cli.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import IntegrationCommands from "./commands/integration.js";
|
|
4
|
+
import AuthCommands from "./commands/login.js";
|
|
5
|
+
|
|
6
|
+
// Create a CLI module with functional approach
|
|
7
|
+
import { findSimilarCommands } from "./helper/command-suggestions.js";
|
|
8
|
+
import { getAllSecrets } from "./helper/secure-storage.js";
|
|
9
|
+
import { setVerboseMode } from "./helper/verbose.js";
|
|
10
|
+
|
|
11
|
+
const createCLI = (consoleUrl, apiUrl, serviceName, env) => {
|
|
12
|
+
const commands = {
|
|
13
|
+
login: {
|
|
14
|
+
description: "Authenticate the user and save access token",
|
|
15
|
+
action: () => AuthCommands.handleLogin(consoleUrl, apiUrl, env),
|
|
16
|
+
},
|
|
17
|
+
integration: {
|
|
18
|
+
description: "Manage integrations (create, list)",
|
|
19
|
+
action: (args) => handleIntegration(args),
|
|
20
|
+
},
|
|
21
|
+
logout: {
|
|
22
|
+
description: "Logout and clear access token",
|
|
23
|
+
action: AuthCommands.handleLogout,
|
|
24
|
+
},
|
|
25
|
+
help: {
|
|
26
|
+
description: "Display this help guide.",
|
|
27
|
+
action: () => showHelp(commands),
|
|
28
|
+
},
|
|
29
|
+
version: {
|
|
30
|
+
description: "Display the version of the CLI.",
|
|
31
|
+
action: () => showVersion(),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
execute: async (args) => {
|
|
37
|
+
// Check for verbose flag
|
|
38
|
+
const verboseIndex = args.indexOf("--verbose");
|
|
39
|
+
if (verboseIndex !== -1) {
|
|
40
|
+
setVerboseMode(true);
|
|
41
|
+
// Remove the verbose flag from args
|
|
42
|
+
args.splice(verboseIndex, 1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const command = args[2];
|
|
46
|
+
|
|
47
|
+
if (!command) {
|
|
48
|
+
showHelp(commands);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!commands[command]) {
|
|
53
|
+
console.log(
|
|
54
|
+
chalk.bgRed.white("\n ❌ Error ") +
|
|
55
|
+
chalk.red(` Unknown command: "${command}""`)
|
|
56
|
+
);
|
|
57
|
+
const suggestions = findSimilarCommands(command, commands);
|
|
58
|
+
|
|
59
|
+
if (suggestions.length > 0) {
|
|
60
|
+
console.log(
|
|
61
|
+
chalk.bgYellow.black("\n 💡 Did you mean: ") +
|
|
62
|
+
chalk.yellow(
|
|
63
|
+
`\n${suggestions.map((cmd) => ` • ${chalk.bold(cmd)} - ${commands[cmd].description}`).join("\n")}\n`
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
showHelp(commands);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Check if user is authenticated for all commands except login and help
|
|
72
|
+
if (command !== "login" && command !== "help") {
|
|
73
|
+
const secrets = await getAllSecrets();
|
|
74
|
+
const userData = secrets?.reduce(
|
|
75
|
+
(acc, { account, password }) => {
|
|
76
|
+
acc[account] = password;
|
|
77
|
+
return acc;
|
|
78
|
+
},
|
|
79
|
+
{}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (!userData?.token?.trim() && !userData?.session?.trim()) {
|
|
83
|
+
console.log(
|
|
84
|
+
chalk.yellow(
|
|
85
|
+
'\nYou are not logged in. Please run "boltic login" first.'
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const commandObj = commands[command];
|
|
93
|
+
await commandObj.action(args.slice(3));
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
async function showHelp(commands) {
|
|
99
|
+
const packageJson = JSON.parse(
|
|
100
|
+
fs.readFileSync(new URL("./package.json", import.meta.url))
|
|
101
|
+
);
|
|
102
|
+
const version = packageJson.version;
|
|
103
|
+
|
|
104
|
+
console.log(chalk.bold.yellow(`\nBoltic CLI Version: ${version}\n`));
|
|
105
|
+
console.log("\nUsage: boltic [command]\n");
|
|
106
|
+
console.log("Available commands:");
|
|
107
|
+
Object.keys(commands).forEach((cmd) => {
|
|
108
|
+
console.log(` ${cmd} - ${commands[cmd].description}`);
|
|
109
|
+
});
|
|
110
|
+
console.log("\nExamples:");
|
|
111
|
+
console.log(" boltic login");
|
|
112
|
+
console.log(" boltic integration create");
|
|
113
|
+
console.log(" boltic help\n");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function handleIntegration(args) {
|
|
117
|
+
await IntegrationCommands.execute(args);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function showVersion() {
|
|
121
|
+
const packageJson = JSON.parse(
|
|
122
|
+
fs.readFileSync(new URL("./package.json", import.meta.url))
|
|
123
|
+
);
|
|
124
|
+
const version = packageJson.version;
|
|
125
|
+
console.log(`Boltic CLI Version: ${version}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default createCLI;
|