@gitbeaker/cli 43.0.0 → 43.2.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 +54 -39
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -7,31 +7,42 @@ 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, decamelize, depascalize } from "xcase";
11
- function param(value) {
12
- let cleaned = value;
13
- const exceptions = [
14
- "GitLabCI",
15
- "YML",
16
- "GPG",
17
- "SSH",
18
- "IId",
19
- "NPM",
20
- "NuGet",
21
- "DORA4",
22
- "LDAP",
23
- "CICD",
24
- "SAML",
25
- "SCIM",
26
- "PyPI"
27
- ];
28
- exceptions.filter((e) => value.includes(e)).forEach((ex) => {
29
- cleaned = cleaned.replace(ex, ex.charAt(0).toUpperCase() + ex.slice(1).toLowerCase());
10
+ import { camelize, decamelize } from "xcase";
11
+ var NORMALIZED_EXCEPTION_TERMS = [
12
+ "GitLabCI",
13
+ "YML",
14
+ "GPG",
15
+ "SSH",
16
+ "IId",
17
+ "NPM",
18
+ "NuGet",
19
+ "DORA4",
20
+ "LDAP",
21
+ "CICD",
22
+ "SAML",
23
+ "SCIM",
24
+ "PyPI"
25
+ ].reduce((prev, cur) => {
26
+ return { ...prev, [cur]: cur.charAt(0).toUpperCase() + cur.slice(1).toLowerCase() };
27
+ }, {});
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);
30
33
  });
31
- const decamelized = decamelize(cleaned, "-");
32
- return decamelized !== cleaned ? decamelized : depascalize(cleaned, "-");
34
+ normalized = normalized.charAt(0).toLowerCase() + normalized.slice(1);
35
+ return decamelize(normalized, "-");
33
36
  }
34
- 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) {
35
46
  const normalized = {};
36
47
  const suffixes = [
37
48
  "TOKEN",
@@ -57,11 +68,12 @@ function buildArgumentObjects(globalConfig, method, rawArgs) {
57
68
  const initArgs = {};
58
69
  Object.entries(rawArgs).forEach(([argName, value]) => {
59
70
  if (ignoreOptions.includes(argName) || value == null) return;
60
- const camelCased = camelize(argName.replace("gb-", "").replace("gl-", ""), "-");
61
- if (globalConfig[argName.replace("gl-", "gb-")]) {
62
- initArgs[camelCased] = value;
63
- } else if (method.args.includes(camelCased)) coreArgs[camelCased] = value;
64
- 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;
65
77
  });
66
78
  return {
67
79
  initArgs,
@@ -82,7 +94,7 @@ function getDisplayConfig(globalConfig) {
82
94
  return display;
83
95
  }
84
96
  function getGlobalConfig(env = process.env) {
85
- const normalEnv = normalizeEnviromentVariables(env);
97
+ const normalEnv = normalizeEnvVariables(env);
86
98
  return {
87
99
  "gb-token": {
88
100
  alias: "gl-token",
@@ -110,7 +122,7 @@ function getGlobalConfig(env = process.env) {
110
122
  },
111
123
  "gb-sudo": {
112
124
  alias: "gl-sudo",
113
- desc: "[Sudo](https://docs.gitlab.com/ee/api/#sudo) query parameter",
125
+ desc: "Sudo query parameter - https://docs.gitlab.com/ee/api/#sudo",
114
126
  type: "string",
115
127
  defaultValue: normalEnv.GITBEAKER_SUDO
116
128
  },
@@ -128,13 +140,13 @@ function getGlobalConfig(env = process.env) {
128
140
  },
129
141
  "gb-profile-token": {
130
142
  alias: "gl-profile-token",
131
- desc: "[Requests Profiles Token](https://docs.gitlab.com/ee/administration/monitoring/performance/request_profiling.html)",
143
+ desc: `Requests Profiles Token - https://docs.gitlab.com/ee/administration/monitoring/performance/request_profiling.html`,
132
144
  type: "string",
133
145
  defaultValue: normalEnv.GITBEAKER_PROFILE_TOKEN
134
146
  },
135
147
  "gb-profile-mode": {
136
148
  alias: "gl-profile-mode",
137
- desc: "[Requests Profiles Token](https://docs.gitlab.com/ee/administration/monitoring/performance/request_profiling.html)",
149
+ desc: "Requests Profiles Token - https://docs.gitlab.com/ee/administration/monitoring/performance/request_profiling.html",
138
150
  type: "string",
139
151
  defaultValue: normalEnv.GITBEAKER_PROFILE_MODE
140
152
  }
@@ -148,10 +160,13 @@ function getExposedAPIs(map) {
148
160
  // src/cli.ts
149
161
  function setupAPIMethods(setupArgs, methodArgs) {
150
162
  methodArgs.forEach((name) => {
151
- setupArgs.positional(`[--${param(name)}] <${param(name)}>`, {
152
- group: "Required Options",
153
- type: "string"
154
- });
163
+ setupArgs.positional(
164
+ `[--${getCLISafeNormalizedTerm(name)}] <${getCLISafeNormalizedTerm(name)}>`,
165
+ {
166
+ group: "Required Options",
167
+ type: "string"
168
+ }
169
+ );
155
170
  });
156
171
  return setupArgs;
157
172
  }
@@ -171,9 +186,9 @@ function setupAPIs(setupArgs, apiName, methods) {
171
186
  ...v
172
187
  });
173
188
  });
174
- for (let i = 1; i < methods.length; i += 1) {
189
+ for (let i = 0; i < methods.length; i += 1) {
175
190
  const method = methods[i];
176
- setupArgs.command(param(method.name), {
191
+ setupArgs.command(getCLISafeNormalizedTerm(method.name), {
177
192
  setup: (setupMethodArgs) => setupAPIMethods(setupMethodArgs, method.args),
178
193
  run: (args, ctx) => runAPIMethod(ctx, args, apiName, method)
179
194
  });
@@ -206,7 +221,7 @@ cli.command("*", (argv, ctx) => {
206
221
  });
207
222
  var exposedAPIs = getExposedAPIs(API_MAP);
208
223
  Object.entries(exposedAPIs).forEach(([apiName, methods]) => {
209
- cli.command(param(apiName), {
224
+ cli.command(getCLISafeNormalizedTerm(apiName), {
210
225
  desc: `The ${apiName} API`,
211
226
  setup: (setupArgs) => setupAPIs(setupArgs, apiName, methods)
212
227
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitbeaker/cli",
3
- "version": "43.0.0",
3
+ "version": "43.2.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.0.0",
43
- "@gitbeaker/rest": "^43.0.0",
42
+ "@gitbeaker/core": "^43.2.0",
43
+ "@gitbeaker/rest": "^43.2.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": "2ae1422a257c0dfe21da6bbfd0f9fd63ea510e85"
52
+ "gitHead": "a0c0b9d3a8b6eeb155ec0c6c3dbee45f7ab31692"
53
53
  }