@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.
Files changed (2) hide show
  1. package/dist/index.mjs +33 -19
  2. 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, depascalize } from "xcase";
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 normalizeTerm(value) {
29
- let normalized = value;
30
- Object.keys(NORMALIZED_EXCEPTION_TERMS).filter((e) => value.includes(e)).forEach((ex) => {
31
- normalized = normalized.replace(ex, NORMALIZED_EXCEPTION_TERMS[ex]);
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
- return depascalize(normalized, "-");
34
+ normalized = normalized.charAt(0).toLowerCase() + normalized.slice(1);
35
+ return decamelize(normalized, "-");
34
36
  }
35
- function normalizeEnviromentVariables(env) {
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 camelCased = camelize(argName.replace("gb-", "").replace("gl-", ""), "-");
62
- if (globalConfig[argName.replace("gl-", "gb-")]) {
63
- initArgs[camelCased] = value;
64
- } else if (method.args.includes(camelCased)) coreArgs[camelCased] = value;
65
- else optionalArgs[camelCased] = value;
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 = normalizeEnviromentVariables(env);
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(`[--${normalizeTerm(name)}] <${normalizeTerm(name)}>`, {
153
- group: "Required Options",
154
- type: "string"
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(normalizeTerm(method.name), {
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(normalizeTerm(apiName), {
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.1.0",
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.1.0",
43
- "@gitbeaker/rest": "^43.1.0",
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": "095f01fd08b131e05910667511276bcafae9888c"
52
+ "gitHead": "f756323a98ca8a6f82a9a29f51e772f3a2a480ab"
53
53
  }