@gitbeaker/cli 43.1.0 → 43.3.0
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/index.mjs +33 -19
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import * as Gitbeaker from "@gitbeaker/rest";
|
|
|
7
7
|
import API_MAP from "@gitbeaker/core/map.json" with { type: "json" };
|
|
8
8
|
|
|
9
9
|
// src/utils.ts
|
|
10
|
-
import { camelize,
|
|
10
|
+
import { camelize, decamelize } from "xcase";
|
|
11
11
|
var NORMALIZED_EXCEPTION_TERMS = [
|
|
12
12
|
"GitLabCI",
|
|
13
13
|
"YML",
|
|
@@ -25,14 +25,24 @@ var NORMALIZED_EXCEPTION_TERMS = [
|
|
|
25
25
|
].reduce((prev, cur) => {
|
|
26
26
|
return { ...prev, [cur]: cur.charAt(0).toUpperCase() + cur.slice(1).toLowerCase() };
|
|
27
27
|
}, {});
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
function getCLISafeNormalizedTerm(term) {
|
|
29
|
+
if (term.length === 0) return term;
|
|
30
|
+
let normalized = term;
|
|
31
|
+
Object.entries(NORMALIZED_EXCEPTION_TERMS).filter(([k]) => term.includes(k)).forEach(([k, v]) => {
|
|
32
|
+
normalized = normalized.replace(k, v);
|
|
32
33
|
});
|
|
33
|
-
|
|
34
|
+
normalized = normalized.charAt(0).toLowerCase() + normalized.slice(1);
|
|
35
|
+
return decamelize(normalized, "-");
|
|
34
36
|
}
|
|
35
|
-
function
|
|
37
|
+
function getAPISafeNormalizedTerm(term) {
|
|
38
|
+
if (term.length === 0) return term;
|
|
39
|
+
let normalized = camelize(term.replace(/(gb|gl)-/g, ""), "-");
|
|
40
|
+
Object.entries(NORMALIZED_EXCEPTION_TERMS).filter(([, v]) => normalized.includes(v)).forEach(([k, v]) => {
|
|
41
|
+
normalized = normalized.replace(v, k);
|
|
42
|
+
});
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
function normalizeEnvVariables(env) {
|
|
36
46
|
const normalized = {};
|
|
37
47
|
const suffixes = [
|
|
38
48
|
"TOKEN",
|
|
@@ -58,11 +68,12 @@ function buildArgumentObjects(globalConfig, method, rawArgs) {
|
|
|
58
68
|
const initArgs = {};
|
|
59
69
|
Object.entries(rawArgs).forEach(([argName, value]) => {
|
|
60
70
|
if (ignoreOptions.includes(argName) || value == null) return;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
else
|
|
71
|
+
const term = argName.replace("gl-", "gb-");
|
|
72
|
+
const normalized = getAPISafeNormalizedTerm(term);
|
|
73
|
+
if (globalConfig[term]) {
|
|
74
|
+
initArgs[normalized] = value;
|
|
75
|
+
} else if (method.args.includes(normalized)) coreArgs[normalized] = value;
|
|
76
|
+
else optionalArgs[normalized] = value;
|
|
66
77
|
});
|
|
67
78
|
return {
|
|
68
79
|
initArgs,
|
|
@@ -83,7 +94,7 @@ function getDisplayConfig(globalConfig) {
|
|
|
83
94
|
return display;
|
|
84
95
|
}
|
|
85
96
|
function getGlobalConfig(env = process.env) {
|
|
86
|
-
const normalEnv =
|
|
97
|
+
const normalEnv = normalizeEnvVariables(env);
|
|
87
98
|
return {
|
|
88
99
|
"gb-token": {
|
|
89
100
|
alias: "gl-token",
|
|
@@ -149,10 +160,13 @@ function getExposedAPIs(map) {
|
|
|
149
160
|
// src/cli.ts
|
|
150
161
|
function setupAPIMethods(setupArgs, methodArgs) {
|
|
151
162
|
methodArgs.forEach((name) => {
|
|
152
|
-
setupArgs.positional(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
163
|
+
setupArgs.positional(
|
|
164
|
+
`[--${getCLISafeNormalizedTerm(name)}] <${getCLISafeNormalizedTerm(name)}>`,
|
|
165
|
+
{
|
|
166
|
+
group: "Required Options",
|
|
167
|
+
type: "string"
|
|
168
|
+
}
|
|
169
|
+
);
|
|
156
170
|
});
|
|
157
171
|
return setupArgs;
|
|
158
172
|
}
|
|
@@ -174,7 +188,7 @@ function setupAPIs(setupArgs, apiName, methods) {
|
|
|
174
188
|
});
|
|
175
189
|
for (let i = 0; i < methods.length; i += 1) {
|
|
176
190
|
const method = methods[i];
|
|
177
|
-
setupArgs.command(
|
|
191
|
+
setupArgs.command(getCLISafeNormalizedTerm(method.name), {
|
|
178
192
|
setup: (setupMethodArgs) => setupAPIMethods(setupMethodArgs, method.args),
|
|
179
193
|
run: (args, ctx) => runAPIMethod(ctx, args, apiName, method)
|
|
180
194
|
});
|
|
@@ -207,7 +221,7 @@ cli.command("*", (argv, ctx) => {
|
|
|
207
221
|
});
|
|
208
222
|
var exposedAPIs = getExposedAPIs(API_MAP);
|
|
209
223
|
Object.entries(exposedAPIs).forEach(([apiName, methods]) => {
|
|
210
|
-
cli.command(
|
|
224
|
+
cli.command(getCLISafeNormalizedTerm(apiName), {
|
|
211
225
|
desc: `The ${apiName} API`,
|
|
212
226
|
setup: (setupArgs) => setupAPIs(setupArgs, apiName, methods)
|
|
213
227
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitbeaker/cli",
|
|
3
|
-
"version": "43.
|
|
3
|
+
"version": "43.3.0",
|
|
4
4
|
"description": "CLI implementation of the GitLab API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"lint:fix": "yarn lint --fix"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@gitbeaker/core": "^43.
|
|
43
|
-
"@gitbeaker/rest": "^43.
|
|
42
|
+
"@gitbeaker/core": "^43.3.0",
|
|
43
|
+
"@gitbeaker/rest": "^43.3.0",
|
|
44
44
|
"chalk": "^5.4.1",
|
|
45
45
|
"sywac": "^1.3.0",
|
|
46
46
|
"xcase": "^2.0.1"
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"tsup": "^8.5.0",
|
|
50
50
|
"typescript": "^5.8.3"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "f756323a98ca8a6f82a9a29f51e772f3a2a480ab"
|
|
53
53
|
}
|