@sap/cli-core 2024.3.0 → 2024.5.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/CHANGELOG.md +64 -0
- package/README.md +1 -1
- package/commands/config.command/cache.command/{init.command.d.ts → init.command/index.d.ts} +1 -1
- package/commands/config.command/cache.command/init.command/index.js +71 -0
- package/commands/config.command/cache.command/init.command/utils.d.ts +3 -0
- package/commands/config.command/cache.command/init.command/utils.js +20 -0
- package/commands/config.command/cache.command/show.command.js +1 -1
- package/commands/config.command/host.command.js +1 -1
- package/commands/config.command/passcode.command.js +1 -1
- package/commands/config.command/secrets.command/reset.command.js +1 -1
- package/commands/config.command/secrets.command/show.command.js +1 -1
- package/commands/handler/authentication/index.js +2 -2
- package/commands/handler/authentication/oauth/index.js +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/file.js +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/index.js +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/options.js +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/index.js +1 -1
- package/commands/handler/authentication/passcode/index.js +1 -1
- package/commands/handler/authentication/technicalJWT/index.js +1 -1
- package/commands/handler/fetch/index.js +1 -1
- package/commands/handler/fetch/utils.js +3 -0
- package/commands/handler/input/file.js +1 -1
- package/commands/handler/input/index.js +1 -1
- package/commands/handler/input/input.js +1 -1
- package/commands/handler/mandatoryOptions.js +1 -1
- package/commands/handler/next.d.ts +1 -1
- package/commands/handler/next.js +8 -2
- package/commands/handler/options/index.js +2 -2
- package/commands/handler/options/utils.js +2 -1
- package/commands/handler/or.d.ts +1 -1
- package/commands/handler/or.js +8 -3
- package/commands/handler/utils.d.ts +1 -0
- package/commands/handler/utils.js +3 -2
- package/commands/login.command.d.ts +2 -1
- package/commands/login.command.js +5 -3
- package/commands/logout.command.js +1 -1
- package/commands/openAPI.command/index.js +1 -1
- package/commands/openAPI.command/utils.js +17 -1
- package/config/core.d.ts +1 -1
- package/config/core.js +3 -3
- package/config/index.js +1 -1
- package/constants.d.ts +14 -1
- package/constants.js +25 -2
- package/discovery/index.js +1 -1
- package/dwc/dwc.js +13 -8
- package/dwc/utils.d.ts +1 -1
- package/dwc/utils.js +4 -4
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +6 -6
- package/types.d.ts +1 -0
- package/utils/commands.d.ts +4 -3
- package/utils/commands.js +43 -31
- package/utils/utils.d.ts +1 -1
- package/utils/utils.js +2 -2
- package/commands/config.command/cache.command/init.command.js +0 -43
|
@@ -30,6 +30,7 @@ const logger_1 = require("../../logger");
|
|
|
30
30
|
const utils_1 = require("../../utils/utils");
|
|
31
31
|
const config_1 = require("../../config");
|
|
32
32
|
const handler_1 = require("../handler");
|
|
33
|
+
const ResultHandlerFactory_1 = require("../../result/ResultHandlerFactory");
|
|
33
34
|
const getLogger = () => (0, logger_1.get)("commands.openAPI.utils");
|
|
34
35
|
const updatePath = (doc, path) => {
|
|
35
36
|
const version = (0, utils_1.parseVersion)(doc.info.version);
|
|
@@ -41,7 +42,10 @@ const updatePath = (doc, path) => {
|
|
|
41
42
|
exports.updatePath = updatePath;
|
|
42
43
|
const isPathParameter = (segment) => /^{.*}$/.test(segment);
|
|
43
44
|
exports.isPathParameter = isPathParameter;
|
|
44
|
-
|
|
45
|
+
function getParameterName(parameter) {
|
|
46
|
+
return `--${(0, lodash_1.kebabCase)(parameter.slice(1, -1))}`;
|
|
47
|
+
}
|
|
48
|
+
const writeParameter = (parameter, value) => `${getParameterName(parameter)} ${value}`;
|
|
45
49
|
exports.writeParameter = writeParameter;
|
|
46
50
|
const getSegments = (value) => {
|
|
47
51
|
const segments = value.split("/");
|
|
@@ -66,14 +70,26 @@ const getPathItem = (doc, operation, path) => {
|
|
|
66
70
|
}
|
|
67
71
|
throw new Error(`path ${operation["x-read-path"]} does not support GET operation`);
|
|
68
72
|
};
|
|
73
|
+
function handleOptions(options, option, value) {
|
|
74
|
+
if ((0, exports.isPathParameter)(option)) {
|
|
75
|
+
return { ...options, [getParameterName(option)]: value };
|
|
76
|
+
}
|
|
77
|
+
return options;
|
|
78
|
+
}
|
|
69
79
|
const outputReadCommand = (doc, operation, response, path) => {
|
|
70
80
|
const locationSegments = (0, exports.getSegments)(response.headers.location);
|
|
71
81
|
const pathSegments = (0, exports.getSegments)(path);
|
|
72
82
|
let params = "";
|
|
83
|
+
let options = {};
|
|
73
84
|
for (let i = 0; i < pathSegments.length; i++) {
|
|
74
85
|
params = handleParameter(params, pathSegments[i], locationSegments[i]);
|
|
86
|
+
options = handleOptions(options, pathSegments[i], locationSegments[i]);
|
|
75
87
|
}
|
|
76
88
|
const pathItem = getPathItem(doc, operation, path);
|
|
89
|
+
ResultHandlerFactory_1.ResultHandlerFactory.get().setResult({
|
|
90
|
+
command: pathItem.get.operationId,
|
|
91
|
+
options,
|
|
92
|
+
});
|
|
77
93
|
const { output } = getLogger();
|
|
78
94
|
output(`Use ${(0, config_1.get)()[constants_1.CLI_NAME]} ${pathItem.get.operationId} ${params} to retrieve the entity you just created`);
|
|
79
95
|
};
|
package/config/core.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AuthenticationMethod } from "../constants";
|
|
|
2
2
|
export declare const getName: () => string;
|
|
3
3
|
export declare const getPackageName: () => string;
|
|
4
4
|
export declare const getDescription: () => string;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const getDiscoveryPaths: () => Array<string>;
|
|
6
6
|
export declare const getSapHelp: () => string;
|
|
7
7
|
export declare const getAuthenticationMethods: () => Array<AuthenticationMethod>;
|
|
8
8
|
export declare const getVersion: () => string;
|
package/config/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGenericOptionsHelp = exports.getDeprecationMessage = exports.isDeprecated = exports.getVersion = exports.getAuthenticationMethods = exports.getSapHelp = exports.
|
|
3
|
+
exports.getGenericOptionsHelp = exports.getDeprecationMessage = exports.isDeprecated = exports.getVersion = exports.getAuthenticationMethods = exports.getSapHelp = exports.getDiscoveryPaths = exports.getDescription = exports.getPackageName = exports.getName = void 0;
|
|
4
4
|
/* jscpd:ignore-start */
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
/* jscpd:ignore-end */
|
|
@@ -11,8 +11,8 @@ const getPackageName = () => (0, index_1.get)()[constants_1.CLI_PACKAGE_NAME];
|
|
|
11
11
|
exports.getPackageName = getPackageName;
|
|
12
12
|
const getDescription = () => (0, index_1.get)()[constants_1.CLI_DESCRIPTION];
|
|
13
13
|
exports.getDescription = getDescription;
|
|
14
|
-
const
|
|
15
|
-
exports.
|
|
14
|
+
const getDiscoveryPaths = () => (0, index_1.get)()[constants_1.CLI_DISCOVERY_PATHS];
|
|
15
|
+
exports.getDiscoveryPaths = getDiscoveryPaths;
|
|
16
16
|
const getSapHelp = () => (0, index_1.get)()[constants_1.CLI_SAP_HELP];
|
|
17
17
|
exports.getSapHelp = getSapHelp;
|
|
18
18
|
const getAuthenticationMethods = () => (0, index_1.get)()[constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS];
|
package/config/index.js
CHANGED
|
@@ -16,7 +16,7 @@ let config;
|
|
|
16
16
|
const CONFIGS_TO_KEEP = [
|
|
17
17
|
constants_1.CONFIG_PASSCODE_FUNCTION,
|
|
18
18
|
constants_1.CLI_DESCRIPTION,
|
|
19
|
-
constants_1.
|
|
19
|
+
constants_1.CLI_DISCOVERY_PATHS,
|
|
20
20
|
constants_1.CLI_NAME,
|
|
21
21
|
constants_1.CLI_PACKAGE_NAME,
|
|
22
22
|
constants_1.CLI_SAP_HELP,
|
package/constants.d.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { Option } from "./types";
|
|
2
2
|
export declare const VERSION: string;
|
|
3
|
+
export type CoreConfiguration = {
|
|
4
|
+
getName: () => string;
|
|
5
|
+
getPackageName: () => string;
|
|
6
|
+
getDescription: () => string;
|
|
7
|
+
getDiscoveryPaths: () => Array<string>;
|
|
8
|
+
getSapHelp: () => string;
|
|
9
|
+
getAuthenticationMethods: () => Array<AuthenticationMethod>;
|
|
10
|
+
getVersion: () => string;
|
|
11
|
+
isDeprecated: () => boolean;
|
|
12
|
+
getDeprecationMessage: () => string;
|
|
13
|
+
getGenericOptionsHelp: () => string;
|
|
14
|
+
};
|
|
3
15
|
export declare const DISCOVERY_DOCUMENT_PREFIX = "discovery-";
|
|
4
16
|
export declare enum AuthenticationMethod {
|
|
5
17
|
oauth = "oauth",
|
|
6
18
|
passcode = "passcode"
|
|
7
19
|
}
|
|
20
|
+
export declare const ROOT_COMMAND_NAME = "ROOT";
|
|
8
21
|
export declare const CLI_NAME = "cli-name";
|
|
9
22
|
export declare const CLI_PACKAGE_NAME = "cli-package-name";
|
|
10
23
|
export declare const CLI_DESCRIPTION = "cli-description";
|
|
11
|
-
export declare const
|
|
24
|
+
export declare const CLI_DISCOVERY_PATHS = "cli-discovery-paths";
|
|
12
25
|
export declare const CLI_SAP_HELP = "cli-sap-help";
|
|
13
26
|
export declare const CLI_VERSION = "cli-version";
|
|
14
27
|
export declare const CLI_DEPRECATED = "cli-deprecated";
|
package/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OPTION_BROWSER = exports.OPTION_INPUT = exports.OPTION_FILE_PATH = exports.OPTION_OPTIONS_FILE = exports.CONFIG_PASSCODE_FUNCTION = exports.OPTION_PASSCODE = exports.OPTION_CODE = exports.OPTION_SECRETS_FILE = exports.OPTION_EXPIRES_IN = exports.OPTION_REFRESH_TOKEN = exports.OPTION_ACCESS_TOKEN = exports.OPTION_TOKEN_URL = exports.OPTION_AUTHORIZATION_URL = exports.OPTION_CLIENT_SECRET = exports.OPTION_CLIENT_ID = exports.OPTION_FORCE = exports.OPTION_VERBOSE = exports.OPTION_NO_PRETTY = exports.OPTION_OUTPUT = exports.OPTION_LOGIN_ID = exports.OPTION_HOST = exports.OPTION_HELP = exports.OPTION_VERSION = exports.CACHE_SECRETS_FILE = exports.PATH_TO_ERROR_HTML = exports.PATH_TO_SUCCESS_HTML = exports.X_OUTPUT_FILE_NAME = exports.X_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_GENERIC_OPTIONS_HELP = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.
|
|
6
|
+
exports.OPTION_BROWSER = exports.OPTION_INPUT = exports.OPTION_FILE_PATH = exports.OPTION_OPTIONS_FILE = exports.CONFIG_PASSCODE_FUNCTION = exports.OPTION_PASSCODE = exports.OPTION_CODE = exports.OPTION_SECRETS_FILE = exports.OPTION_EXPIRES_IN = exports.OPTION_REFRESH_TOKEN = exports.OPTION_ACCESS_TOKEN = exports.OPTION_TOKEN_URL = exports.OPTION_AUTHORIZATION_URL = exports.OPTION_CLIENT_SECRET = exports.OPTION_CLIENT_ID = exports.OPTION_FORCE = exports.OPTION_VERBOSE = exports.OPTION_NO_PRETTY = exports.OPTION_OUTPUT = exports.OPTION_LOGIN_ID = exports.OPTION_HOST = exports.OPTION_HELP = exports.OPTION_VERSION = exports.CACHE_SECRETS_FILE = exports.PATH_TO_ERROR_HTML = exports.PATH_TO_SUCCESS_HTML = exports.X_OUTPUT_FILE_NAME = exports.X_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_GENERIC_OPTIONS_HELP = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.CLI_DISCOVERY_PATHS = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.ROOT_COMMAND_NAME = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const utils_1 = require("./utils/utils");
|
|
9
9
|
exports.VERSION = (0, utils_1.getVersion)();
|
|
@@ -13,10 +13,11 @@ var AuthenticationMethod;
|
|
|
13
13
|
AuthenticationMethod["oauth"] = "oauth";
|
|
14
14
|
AuthenticationMethod["passcode"] = "passcode";
|
|
15
15
|
})(AuthenticationMethod || (exports.AuthenticationMethod = AuthenticationMethod = {}));
|
|
16
|
+
exports.ROOT_COMMAND_NAME = "ROOT";
|
|
16
17
|
exports.CLI_NAME = "cli-name";
|
|
17
18
|
exports.CLI_PACKAGE_NAME = "cli-package-name";
|
|
18
19
|
exports.CLI_DESCRIPTION = "cli-description";
|
|
19
|
-
exports.
|
|
20
|
+
exports.CLI_DISCOVERY_PATHS = "cli-discovery-paths";
|
|
20
21
|
exports.CLI_SAP_HELP = "cli-sap-help";
|
|
21
22
|
exports.CLI_VERSION = "cli-version";
|
|
22
23
|
exports.CLI_DEPRECATED = "cli-deprecated";
|
|
@@ -31,17 +32,20 @@ exports.PATH_TO_SUCCESS_HTML = path_1.default.join(__dirname, "assets", "success
|
|
|
31
32
|
exports.PATH_TO_ERROR_HTML = path_1.default.join(__dirname, "assets", "error.html");
|
|
32
33
|
exports.CACHE_SECRETS_FILE = "secrets.json";
|
|
33
34
|
exports.OPTION_VERSION = {
|
|
35
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
34
36
|
longName: "version",
|
|
35
37
|
description: "print version",
|
|
36
38
|
hidden: true,
|
|
37
39
|
};
|
|
38
40
|
exports.OPTION_HELP = {
|
|
41
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
39
42
|
longName: "help",
|
|
40
43
|
description: "print help for a command",
|
|
41
44
|
args: [{ name: "command" }],
|
|
42
45
|
hidden: true,
|
|
43
46
|
};
|
|
44
47
|
exports.OPTION_HOST = {
|
|
48
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
45
49
|
longName: "host",
|
|
46
50
|
description: "specifies the url where the tenant is hosted",
|
|
47
51
|
args: [{ name: "host" }],
|
|
@@ -52,6 +56,7 @@ exports.OPTION_HOST = {
|
|
|
52
56
|
},
|
|
53
57
|
};
|
|
54
58
|
exports.OPTION_LOGIN_ID = {
|
|
59
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
55
60
|
longName: "login-id",
|
|
56
61
|
description: "specifies the login ID",
|
|
57
62
|
args: [{ name: "id" }],
|
|
@@ -63,26 +68,31 @@ exports.OPTION_LOGIN_ID = {
|
|
|
63
68
|
},
|
|
64
69
|
};
|
|
65
70
|
exports.OPTION_OUTPUT = {
|
|
71
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
66
72
|
longName: "output",
|
|
67
73
|
description: "specifies the file to store the output of the command",
|
|
68
74
|
args: [{ name: "output", optional: true }],
|
|
69
75
|
hidden: true,
|
|
70
76
|
};
|
|
71
77
|
exports.OPTION_NO_PRETTY = {
|
|
78
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
72
79
|
longName: "no-pretty",
|
|
73
80
|
description: "do not pretty-format JSON responses",
|
|
74
81
|
hidden: true,
|
|
75
82
|
};
|
|
76
83
|
exports.OPTION_VERBOSE = {
|
|
84
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
77
85
|
longName: "verbose",
|
|
78
86
|
description: "print detailed log information to console",
|
|
79
87
|
hidden: true,
|
|
80
88
|
};
|
|
81
89
|
exports.OPTION_FORCE = {
|
|
90
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
82
91
|
longName: "force",
|
|
83
92
|
description: "force the command execution",
|
|
84
93
|
};
|
|
85
94
|
exports.OPTION_CLIENT_ID = {
|
|
95
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
86
96
|
longName: "client-id",
|
|
87
97
|
description: "client id for interactive oauth session authentication",
|
|
88
98
|
args: [{ name: "id" }],
|
|
@@ -93,6 +103,7 @@ exports.OPTION_CLIENT_ID = {
|
|
|
93
103
|
},
|
|
94
104
|
};
|
|
95
105
|
exports.OPTION_CLIENT_SECRET = {
|
|
106
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
96
107
|
longName: "client-secret",
|
|
97
108
|
description: "client secret for interactive oauth session authentication",
|
|
98
109
|
args: [{ name: "secret" }],
|
|
@@ -103,6 +114,7 @@ exports.OPTION_CLIENT_SECRET = {
|
|
|
103
114
|
},
|
|
104
115
|
};
|
|
105
116
|
exports.OPTION_AUTHORIZATION_URL = {
|
|
117
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
106
118
|
longName: "authorization-url",
|
|
107
119
|
description: "authorization url for interactive oauth session authentication",
|
|
108
120
|
args: [{ name: "url" }],
|
|
@@ -113,6 +125,7 @@ exports.OPTION_AUTHORIZATION_URL = {
|
|
|
113
125
|
},
|
|
114
126
|
};
|
|
115
127
|
exports.OPTION_TOKEN_URL = {
|
|
128
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
116
129
|
longName: "token-url",
|
|
117
130
|
description: "token url for interactive oauth session authentication",
|
|
118
131
|
args: [{ name: "url" }],
|
|
@@ -123,6 +136,7 @@ exports.OPTION_TOKEN_URL = {
|
|
|
123
136
|
},
|
|
124
137
|
};
|
|
125
138
|
exports.OPTION_ACCESS_TOKEN = {
|
|
139
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
126
140
|
longName: "access-token",
|
|
127
141
|
description: "access token for interactive oauth session authentication",
|
|
128
142
|
args: [{ name: "token" }],
|
|
@@ -133,6 +147,7 @@ exports.OPTION_ACCESS_TOKEN = {
|
|
|
133
147
|
},
|
|
134
148
|
};
|
|
135
149
|
exports.OPTION_REFRESH_TOKEN = {
|
|
150
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
136
151
|
longName: "refresh-token",
|
|
137
152
|
description: "refresh token for interactive oauth session authentication",
|
|
138
153
|
args: [{ name: "token" }],
|
|
@@ -143,6 +158,7 @@ exports.OPTION_REFRESH_TOKEN = {
|
|
|
143
158
|
},
|
|
144
159
|
};
|
|
145
160
|
exports.OPTION_EXPIRES_IN = {
|
|
161
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
146
162
|
longName: "expires-in",
|
|
147
163
|
description: "expires in information for interactive oauth session authentication",
|
|
148
164
|
args: [{ name: "expires" }],
|
|
@@ -153,6 +169,7 @@ exports.OPTION_EXPIRES_IN = {
|
|
|
153
169
|
},
|
|
154
170
|
};
|
|
155
171
|
exports.OPTION_SECRETS_FILE = {
|
|
172
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
156
173
|
longName: "secrets-file",
|
|
157
174
|
description: "path to secrets file",
|
|
158
175
|
args: [{ name: "file" }],
|
|
@@ -163,6 +180,7 @@ exports.OPTION_SECRETS_FILE = {
|
|
|
163
180
|
},
|
|
164
181
|
};
|
|
165
182
|
exports.OPTION_CODE = {
|
|
183
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
166
184
|
longName: "code",
|
|
167
185
|
description: "code for oauth token retrieval",
|
|
168
186
|
args: [{ name: "code" }],
|
|
@@ -173,6 +191,7 @@ exports.OPTION_CODE = {
|
|
|
173
191
|
},
|
|
174
192
|
};
|
|
175
193
|
exports.OPTION_PASSCODE = {
|
|
194
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
176
195
|
longName: "passcode",
|
|
177
196
|
description: "passcode for interactive session authentication",
|
|
178
197
|
args: [{ name: "passcode" }],
|
|
@@ -180,12 +199,14 @@ exports.OPTION_PASSCODE = {
|
|
|
180
199
|
};
|
|
181
200
|
exports.CONFIG_PASSCODE_FUNCTION = "passcodeFunction";
|
|
182
201
|
exports.OPTION_OPTIONS_FILE = {
|
|
202
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
183
203
|
longName: "options-file",
|
|
184
204
|
description: "path to options file",
|
|
185
205
|
args: [{ name: "file" }],
|
|
186
206
|
hidden: true,
|
|
187
207
|
};
|
|
188
208
|
exports.OPTION_FILE_PATH = {
|
|
209
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
189
210
|
longName: "file-path",
|
|
190
211
|
description: "specifies the file to use as input for the command",
|
|
191
212
|
args: [{ name: "path" }],
|
|
@@ -195,6 +216,7 @@ exports.OPTION_FILE_PATH = {
|
|
|
195
216
|
},
|
|
196
217
|
};
|
|
197
218
|
exports.OPTION_INPUT = {
|
|
219
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
198
220
|
longName: "input",
|
|
199
221
|
description: "specifies input as string to use for the command",
|
|
200
222
|
args: [{ name: "input" }],
|
|
@@ -204,6 +226,7 @@ exports.OPTION_INPUT = {
|
|
|
204
226
|
},
|
|
205
227
|
};
|
|
206
228
|
exports.OPTION_BROWSER = {
|
|
229
|
+
commandName: exports.ROOT_COMMAND_NAME,
|
|
207
230
|
longName: "browser",
|
|
208
231
|
description: "specifies the browser to open",
|
|
209
232
|
args: [{ name: "browser" }],
|
package/discovery/index.js
CHANGED
|
@@ -20,7 +20,7 @@ let metadata;
|
|
|
20
20
|
const getDocumentName = () => {
|
|
21
21
|
const { trace } = getLogger();
|
|
22
22
|
const config = (0, config_1.get)();
|
|
23
|
-
const sha = (0, utils_2.sha256)(`${config.publicfqdn}${(0, core_1.
|
|
23
|
+
const sha = (0, utils_2.sha256)(`${config.publicfqdn}${JSON.stringify((0, core_1.getDiscoveryPaths)())}`).replace(/[/\\]/g, "_");
|
|
24
24
|
const name = `${constants_1.DISCOVERY_DOCUMENT_PREFIX}${sha}.json`;
|
|
25
25
|
trace(`calculating document name for host ${config.host}, name ${name}`);
|
|
26
26
|
return name;
|
package/dwc/dwc.js
CHANGED
|
@@ -23,6 +23,7 @@ const ResultHandlerImpl_1 = require("../result/ResultHandlerImpl");
|
|
|
23
23
|
const ResultHandlerFactory_1 = require("../result/ResultHandlerFactory");
|
|
24
24
|
const SecretsStorageImpl_1 = require("../cache/secrets/SecretsStorageImpl");
|
|
25
25
|
const SecretsStorageSingleton_1 = require("../cache/secrets/SecretsStorageSingleton");
|
|
26
|
+
const utils_3 = require("../commands/handler/utils");
|
|
26
27
|
let program;
|
|
27
28
|
let initialized = false;
|
|
28
29
|
const getLogger = () => (0, logger_1.get)("dwc.dwc");
|
|
@@ -42,9 +43,9 @@ const setTenant = async () => {
|
|
|
42
43
|
if (config.host) {
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
|
-
const readHostFromArgv = async () => (0, utils_1.getOptionValueFromArgv)(constants_1.OPTION_HOST);
|
|
46
|
+
const readHostFromArgv = async () => (0, utils_1.getOptionValueFromArgv)(constants_1.ROOT_COMMAND_NAME, constants_1.OPTION_HOST);
|
|
46
47
|
const readHostFromOptionsFile = async () => {
|
|
47
|
-
const filePath = (0, utils_1.getOptionValueFromArgv)(constants_1.OPTION_OPTIONS_FILE);
|
|
48
|
+
const filePath = (0, utils_1.getOptionValueFromArgv)(constants_1.ROOT_COMMAND_NAME, constants_1.OPTION_OPTIONS_FILE);
|
|
48
49
|
return (0, utils_2.getValueFromOptionsFile)(filePath, constants_1.OPTION_HOST);
|
|
49
50
|
};
|
|
50
51
|
const readHostFromOptions = async () => {
|
|
@@ -72,8 +73,12 @@ const setTenant = async () => {
|
|
|
72
73
|
trace(`trying to ${name}`);
|
|
73
74
|
try {
|
|
74
75
|
// eslint-disable-next-line no-await-in-loop
|
|
75
|
-
const host = await func();
|
|
76
|
-
(0, config_1.set)({
|
|
76
|
+
const host = (0, utils_3.replaceLeadingTrailingSingleQuotes)(await func());
|
|
77
|
+
(0, config_1.set)({
|
|
78
|
+
tenant: host,
|
|
79
|
+
options: { ...config.options, [constants_1.OPTION_HOST.longName]: host },
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
77
82
|
}
|
|
78
83
|
catch (err) {
|
|
79
84
|
trace(`failed to ${name}`, err);
|
|
@@ -95,7 +100,7 @@ const initCacheTolerant = async () => {
|
|
|
95
100
|
}
|
|
96
101
|
};
|
|
97
102
|
const registerMandatoryOptions = () => {
|
|
98
|
-
MANDATORY_OPTIONS.forEach((option) => (0, commands_1.registerLongName)(option
|
|
103
|
+
MANDATORY_OPTIONS.forEach((option) => (0, commands_1.registerLongName)(constants_1.ROOT_COMMAND_NAME, option));
|
|
99
104
|
};
|
|
100
105
|
async function setupSecretsStorage() {
|
|
101
106
|
const instance = new SecretsStorageImpl_1.SecretsStorageImpl();
|
|
@@ -124,8 +129,8 @@ const init = async () => {
|
|
|
124
129
|
` config host set "<Server_URL>". Did you initialize the CLI by running ${cliName} config` +
|
|
125
130
|
` cache init --host "<Server_URL>"?` +
|
|
126
131
|
` Add option --help, -h or go to ${(0, config_1.get)()[constants_1.CLI_SAP_HELP]} for additional information.`);
|
|
127
|
-
program.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_HOST));
|
|
128
|
-
program.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_OPTIONS_FILE));
|
|
132
|
+
program.addOption(await (0, commands_1.buildOption)(constants_1.ROOT_COMMAND_NAME, constants_1.OPTION_HOST));
|
|
133
|
+
program.addOption(await (0, commands_1.buildOption)(constants_1.ROOT_COMMAND_NAME, constants_1.OPTION_OPTIONS_FILE));
|
|
129
134
|
program.configureHelp({ sortSubcommands: true });
|
|
130
135
|
program.addHelpText("afterAll", `Only command-specific options are listed here. To learn more about available generic options,` +
|
|
131
136
|
` visit ${(0, core_1.getGenericOptionsHelp)()}`);
|
|
@@ -135,7 +140,7 @@ const init = async () => {
|
|
|
135
140
|
};
|
|
136
141
|
exports.init = init;
|
|
137
142
|
const executeCommand = async (command) => {
|
|
138
|
-
await program.parseAsync(command?.split(" ")
|
|
143
|
+
await program.parseAsync(command?.split(" ") ?? undefined);
|
|
139
144
|
};
|
|
140
145
|
exports.executeCommand = executeCommand;
|
|
141
146
|
const buildCommandsObject = (name, command, object = {}) => {
|
package/dwc/utils.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export declare const addCommandsFromFolder: (pathToFolder: string, program: Comm
|
|
|
4
4
|
export declare function verifyNodeVersion(): void;
|
|
5
5
|
export declare const checkVersion: () => Promise<void>;
|
|
6
6
|
export declare const compareEtags: () => Promise<void>;
|
|
7
|
-
export declare const getOptionValueFromArgv: (
|
|
7
|
+
export declare const getOptionValueFromArgv: (commandName: string, option: Option) => string;
|
package/dwc/utils.js
CHANGED
|
@@ -69,12 +69,12 @@ const compareEtags = async () => {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
exports.compareEtags = compareEtags;
|
|
72
|
-
const getOptionValueFromArgv = (
|
|
73
|
-
const shortFlag = (0, commands_1.getShortFlagForLongName)(
|
|
74
|
-
const index = process.argv.findIndex((a) => a === `-${shortFlag}` || a === `--${longName}`);
|
|
72
|
+
const getOptionValueFromArgv = (commandName, option) => {
|
|
73
|
+
const shortFlag = (0, commands_1.getShortFlagForLongName)(commandName, option);
|
|
74
|
+
const index = process.argv.findIndex((a) => a === `-${shortFlag}` || a === `--${option.longName}`);
|
|
75
75
|
if (index > -1) {
|
|
76
76
|
return process.argv[index + 1];
|
|
77
77
|
}
|
|
78
|
-
throw new Error(`option ${longName} not found in argv`);
|
|
78
|
+
throw new Error(`option ${option.longName} not found in argv`);
|
|
79
79
|
};
|
|
80
80
|
exports.getOptionValueFromArgv = getOptionValueFromArgv;
|
package/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export { run } from "./dwc/run";
|
|
|
3
3
|
export { configure, getCommands } from "./module";
|
|
4
4
|
export { AuthenticationMethod };
|
|
5
5
|
export { getVersion, getBin, getDescription, getName, getPackageName, } from "./utils/utils";
|
|
6
|
-
export declare const configureCoreModule: ({ name, packageName,
|
|
6
|
+
export declare const configureCoreModule: ({ name, packageName, discoveryPaths, description, sapHelpLink, authenticationMethods, version, genericOptionsHelp, deprecated, deprecationMessage, }: {
|
|
7
7
|
name: string;
|
|
8
8
|
packageName: string;
|
|
9
|
-
|
|
9
|
+
discoveryPaths: Array<string>;
|
|
10
10
|
description: string;
|
|
11
11
|
sapHelpLink: string;
|
|
12
12
|
authenticationMethods?: AuthenticationMethod[] | undefined;
|
package/index.js
CHANGED
|
@@ -45,12 +45,12 @@ Object.defineProperty(exports, "getBin", { enumerable: true, get: function () {
|
|
|
45
45
|
Object.defineProperty(exports, "getDescription", { enumerable: true, get: function () { return utils_1.getDescription; } });
|
|
46
46
|
Object.defineProperty(exports, "getName", { enumerable: true, get: function () { return utils_1.getName; } });
|
|
47
47
|
Object.defineProperty(exports, "getPackageName", { enumerable: true, get: function () { return utils_1.getPackageName; } });
|
|
48
|
-
const configureCoreModule = ({ name, packageName,
|
|
48
|
+
const configureCoreModule = ({ name, packageName, discoveryPaths, description, sapHelpLink, authenticationMethods = [constants_1.AuthenticationMethod.oauth], version, genericOptionsHelp, deprecated = false, deprecationMessage, }) => {
|
|
49
49
|
(0, config_1.set)({
|
|
50
50
|
[constants_1.CLI_NAME]: name,
|
|
51
51
|
[constants_1.CLI_PACKAGE_NAME]: packageName,
|
|
52
52
|
[constants_1.CLI_DESCRIPTION]: description,
|
|
53
|
-
[constants_1.
|
|
53
|
+
[constants_1.CLI_DISCOVERY_PATHS]: discoveryPaths,
|
|
54
54
|
[constants_1.CLI_SAP_HELP]: sapHelpLink,
|
|
55
55
|
[constants_1.CLI_SUPPORTED_AUTHENTICATION_METHODS]: authenticationMethods,
|
|
56
56
|
[constants_1.CLI_VERSION]: version,
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap/cli-core",
|
|
3
|
-
"version": "2024.
|
|
3
|
+
"version": "2024.5.0",
|
|
4
4
|
"description": "Command-Line Interface (CLI) Core Module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "SAP SE",
|
|
7
7
|
"homepage": "https://www.sap.com",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": "^20",
|
|
11
|
-
"npm": "^10"
|
|
10
|
+
"node": "^18 || ^19 || ^20 || ^21",
|
|
11
|
+
"npm": "^9 || ^10"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"cli",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"ajv": "8.12.0",
|
|
21
|
-
"axios": "1.6.
|
|
21
|
+
"axios": "1.6.7",
|
|
22
22
|
"commander": "11.1.0",
|
|
23
23
|
"compare-versions": "6.1.0",
|
|
24
|
-
"config": "3.3.
|
|
25
|
-
"dotenv": "16.
|
|
24
|
+
"config": "3.3.10",
|
|
25
|
+
"dotenv": "16.4.1",
|
|
26
26
|
"fs-extra": "11.2.0",
|
|
27
27
|
"https": "1.0.0",
|
|
28
28
|
"https-proxy-agent": "7.0.2",
|
package/types.d.ts
CHANGED
|
@@ -144,6 +144,7 @@ export type DefaultFunction = () => Promise<string>;
|
|
|
144
144
|
export type ChoicesFunction = () => Promise<Array<string>>;
|
|
145
145
|
export type Choices = Array<string>;
|
|
146
146
|
export type Option = {
|
|
147
|
+
commandName?: string;
|
|
147
148
|
longName: string;
|
|
148
149
|
description: string;
|
|
149
150
|
default?: string | DefaultFunction;
|
package/utils/commands.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import commander, { Command, Option } from "commander";
|
|
2
2
|
import { Command as CommandType, Option as OptionType } from "../types";
|
|
3
3
|
export declare const createCommand: (name?: string) => Command;
|
|
4
|
-
export declare
|
|
4
|
+
export declare function getCommandNameForShortFlag(commandName: string, option: OptionType): string;
|
|
5
|
+
export declare const getShortFlagForLongName: (commandName: string, option: OptionType) => string;
|
|
5
6
|
export declare const isOptionAlreadyRegistered: ({ longName }: OptionType, command: Command) => boolean;
|
|
6
|
-
export declare const registerLongName: (
|
|
7
|
-
export declare const buildOption: (
|
|
7
|
+
export declare const registerLongName: (commandName: string, option: OptionType) => string;
|
|
8
|
+
export declare const buildOption: (commandName: string, option: OptionType) => Promise<Option>;
|
|
8
9
|
export declare const buildCommand: (topCommand: commander.Command, command: CommandType) => Promise<commander.Command>;
|
package/utils/commands.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildCommand = exports.buildOption = exports.registerLongName = exports.isOptionAlreadyRegistered = exports.getShortFlagForLongName = exports.createCommand = void 0;
|
|
3
|
+
exports.buildCommand = exports.buildOption = exports.registerLongName = exports.isOptionAlreadyRegistered = exports.getShortFlagForLongName = exports.getCommandNameForShortFlag = exports.createCommand = void 0;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const root_1 = require("../commands/handler/root");
|
|
@@ -34,13 +34,18 @@ const createCommand = (name) => {
|
|
|
34
34
|
return command;
|
|
35
35
|
};
|
|
36
36
|
exports.createCommand = createCommand;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
function getCommandNameForShortFlag(commandName, option) {
|
|
38
|
+
return option.commandName ?? commandName;
|
|
39
|
+
}
|
|
40
|
+
exports.getCommandNameForShortFlag = getCommandNameForShortFlag;
|
|
41
|
+
const getShortFlagForLongName = (commandName, option) => {
|
|
42
|
+
const cName = getCommandNameForShortFlag(commandName, option);
|
|
43
|
+
for (const s of Object.keys(registeredOptions[cName] ?? {})) {
|
|
44
|
+
if (registeredOptions[cName][s] === option.longName) {
|
|
40
45
|
return s;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
|
-
throw new Error(`no short flag registered for long name ${longName}`);
|
|
48
|
+
throw new Error(`no short flag registered for command ${cName}, long name ${option.longName}`);
|
|
44
49
|
};
|
|
45
50
|
exports.getShortFlagForLongName = getShortFlagForLongName;
|
|
46
51
|
const isOptionAlreadyRegistered = ({ longName }, command) => {
|
|
@@ -48,52 +53,59 @@ const isOptionAlreadyRegistered = ({ longName }, command) => {
|
|
|
48
53
|
return !!opts?.includes(longName);
|
|
49
54
|
};
|
|
50
55
|
exports.isOptionAlreadyRegistered = isOptionAlreadyRegistered;
|
|
51
|
-
const registerLongName = (
|
|
56
|
+
const registerLongName = (commandName, option) => {
|
|
57
|
+
const cName = getCommandNameForShortFlag(commandName, option);
|
|
52
58
|
try {
|
|
53
|
-
return (0, exports.getShortFlagForLongName)(
|
|
59
|
+
return (0, exports.getShortFlagForLongName)(cName, option);
|
|
54
60
|
}
|
|
55
61
|
catch (err) {
|
|
56
62
|
for (const c of [
|
|
57
|
-
longName[0],
|
|
58
|
-
longName[0].toUpperCase() === longName[0]
|
|
59
|
-
? longName[0].toLowerCase()
|
|
60
|
-
: longName[0].toUpperCase(),
|
|
63
|
+
option.longName[0],
|
|
64
|
+
option.longName[0].toUpperCase() === option.longName[0]
|
|
65
|
+
? option.longName[0].toLowerCase()
|
|
66
|
+
: option.longName[0].toUpperCase(),
|
|
61
67
|
...types_1.CHARACTERS,
|
|
62
68
|
]) {
|
|
63
|
-
if (!registeredOptions[c]) {
|
|
64
|
-
registeredOptions[
|
|
69
|
+
if (!registeredOptions[cName]?.[c]) {
|
|
70
|
+
registeredOptions[cName] = registeredOptions[cName] ?? {};
|
|
71
|
+
registeredOptions[cName][c] = option.longName;
|
|
65
72
|
return c;
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
|
-
throw new Error(`no short flag found for name ${longName}`);
|
|
75
|
+
throw new Error(`no short flag found for name ${option.longName}, command ${cName}`);
|
|
69
76
|
}
|
|
70
77
|
};
|
|
71
78
|
exports.registerLongName = registerLongName;
|
|
72
|
-
const buildOption = async (
|
|
73
|
-
const mandatory = !!required;
|
|
74
|
-
const shortFlag = (0, exports.registerLongName)(
|
|
75
|
-
let newDescr = description;
|
|
79
|
+
const buildOption = async (commandName, option) => {
|
|
80
|
+
const mandatory = !!option.required;
|
|
81
|
+
const shortFlag = (0, exports.registerLongName)(commandName, option);
|
|
82
|
+
let newDescr = option.description;
|
|
76
83
|
if (!mandatory) {
|
|
77
84
|
newDescr = newDescr ? `${newDescr} (optional)` : "(optional)";
|
|
78
85
|
}
|
|
79
|
-
const argStr = args
|
|
80
|
-
? args.reduce((p, c) => (c.optional ? `${p} [${c.name}]` : `${p} <${c.name}>`), "")
|
|
86
|
+
const argStr = option.args
|
|
87
|
+
? option.args.reduce((p, c) => (c.optional ? `${p} [${c.name}]` : `${p} <${c.name}>`), "")
|
|
81
88
|
: "";
|
|
82
|
-
const
|
|
89
|
+
const cOption = new commander_1.Option(`-${shortFlag}, --${option.longName}${argStr}`, newDescr)
|
|
83
90
|
.makeOptionMandatory(mandatory)
|
|
84
|
-
.hideHelp(!!hidden);
|
|
85
|
-
if (
|
|
86
|
-
const defaultStr = typeof
|
|
87
|
-
|
|
91
|
+
.hideHelp(!!option.hidden);
|
|
92
|
+
if (option.default) {
|
|
93
|
+
const defaultStr = typeof option.default === "function"
|
|
94
|
+
? await option.default()
|
|
95
|
+
: option.default;
|
|
96
|
+
cOption.default(defaultStr);
|
|
88
97
|
}
|
|
89
98
|
let choicesArr = [];
|
|
90
|
-
if (choices) {
|
|
91
|
-
choicesArr =
|
|
99
|
+
if (option.choices) {
|
|
100
|
+
choicesArr =
|
|
101
|
+
typeof option.choices === "function"
|
|
102
|
+
? await option.choices()
|
|
103
|
+
: option.choices;
|
|
92
104
|
}
|
|
93
105
|
if (choicesArr.length > 0) {
|
|
94
|
-
|
|
106
|
+
cOption.choices(choicesArr);
|
|
95
107
|
}
|
|
96
|
-
return
|
|
108
|
+
return cOption;
|
|
97
109
|
};
|
|
98
110
|
exports.buildOption = buildOption;
|
|
99
111
|
const buildCommand = async (topCommand, command) => {
|
|
@@ -104,9 +116,9 @@ const buildCommand = async (topCommand, command) => {
|
|
|
104
116
|
const comm = (0, exports.createCommand)(name);
|
|
105
117
|
comm.description(description);
|
|
106
118
|
comm.enablePositionalOptions();
|
|
107
|
-
for (const option of options
|
|
119
|
+
for (const option of options ?? []) {
|
|
108
120
|
// eslint-disable-next-line no-await-in-loop
|
|
109
|
-
comm.addOption(await (0, exports.buildOption)(option));
|
|
121
|
+
comm.addOption(await (0, exports.buildOption)(name, option));
|
|
110
122
|
}
|
|
111
123
|
if (command.type === "topCommand") {
|
|
112
124
|
const { subCommands } = command;
|
package/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Option, PackageJson } from "../types";
|
|
2
|
-
export declare function buildOptionName(option: Option): string;
|
|
2
|
+
export declare function buildOptionName(commandName: string, option: Option): string;
|
|
3
3
|
export declare const parseVersion: (version: string) => {
|
|
4
4
|
major: number;
|
|
5
5
|
minor: number;
|
package/utils/utils.js
CHANGED
|
@@ -35,8 +35,8 @@ const commands_1 = require("./commands");
|
|
|
35
35
|
let pgk;
|
|
36
36
|
const getLogger = () => (0, logger_1.get)("utils.utils");
|
|
37
37
|
const REGEX_HTTPS = /http(s)*:\/\//;
|
|
38
|
-
function buildOptionName(option) {
|
|
39
|
-
const shortFlag = (0, commands_1.getShortFlagForLongName)(option
|
|
38
|
+
function buildOptionName(commandName, option) {
|
|
39
|
+
const shortFlag = (0, commands_1.getShortFlagForLongName)(commandName, option);
|
|
40
40
|
return `-${shortFlag}, --${option.longName}`;
|
|
41
41
|
}
|
|
42
42
|
exports.buildOptionName = buildOptionName;
|