@sap/cli-core 2024.4.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/commands/config.command/cache.command/init.command/index.js +1 -1
  3. package/commands/config.command/cache.command/show.command.js +1 -1
  4. package/commands/config.command/host.command.js +1 -1
  5. package/commands/config.command/passcode.command.js +1 -1
  6. package/commands/config.command/secrets.command/reset.command.js +1 -1
  7. package/commands/config.command/secrets.command/show.command.js +1 -1
  8. package/commands/handler/authentication/index.js +2 -2
  9. package/commands/handler/authentication/oauth/index.js +1 -1
  10. package/commands/handler/authentication/oauth/secretsProvider/file.js +1 -1
  11. package/commands/handler/authentication/oauth/secretsProvider/index.js +1 -1
  12. package/commands/handler/authentication/oauth/secretsProvider/options.js +1 -1
  13. package/commands/handler/authentication/oauth/tokenProvider/getToken.js +1 -1
  14. package/commands/handler/authentication/oauth/tokenProvider/index.js +1 -1
  15. package/commands/handler/authentication/passcode/index.js +1 -1
  16. package/commands/handler/authentication/technicalJWT/index.js +1 -1
  17. package/commands/handler/fetch/index.js +1 -1
  18. package/commands/handler/input/file.js +1 -1
  19. package/commands/handler/input/index.js +1 -1
  20. package/commands/handler/input/input.js +1 -1
  21. package/commands/handler/mandatoryOptions.js +1 -1
  22. package/commands/handler/next.d.ts +1 -1
  23. package/commands/handler/next.js +8 -2
  24. package/commands/handler/options/index.js +2 -2
  25. package/commands/handler/options/utils.js +2 -1
  26. package/commands/handler/or.d.ts +1 -1
  27. package/commands/handler/or.js +8 -3
  28. package/commands/handler/utils.d.ts +1 -0
  29. package/commands/handler/utils.js +3 -2
  30. package/commands/login.command.d.ts +2 -1
  31. package/commands/login.command.js +5 -3
  32. package/commands/logout.command.js +1 -1
  33. package/commands/openAPI.command/index.js +1 -1
  34. package/constants.d.ts +1 -0
  35. package/constants.js +24 -1
  36. package/dwc/dwc.js +8 -7
  37. package/dwc/utils.d.ts +1 -1
  38. package/dwc/utils.js +4 -4
  39. package/package.json +3 -3
  40. package/types.d.ts +1 -0
  41. package/utils/commands.d.ts +4 -3
  42. package/utils/commands.js +42 -30
  43. package/utils/utils.d.ts +1 -1
  44. package/utils/utils.js +2 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 2024.5.0
9
+
10
+ ### Fixed
11
+
12
+ - Fixed an issue with parsing the discovery document if more than 52 distinct options are defined. Now, the short flags are calculated per command. This allows for having up to 52 options per command. However, the same option used across different commands might not share the same short flag depending on other available options for the commands. It is recommended to always use the option's long name as the long name remains stable.
13
+
8
14
  ## 2024.4.0
9
15
 
10
16
  ### Added
@@ -66,6 +66,6 @@ const initCommand = {
66
66
  command: "init",
67
67
  description: "initialize the local CLI cache",
68
68
  options: [],
69
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), exports.init),
69
+ handler: (0, handler_1.createNextHandler)("command.config.cache.init", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), exports.init),
70
70
  };
71
71
  exports.default = initCommand;
@@ -25,6 +25,6 @@ const showCommand = {
25
25
  type: "command",
26
26
  command: "show",
27
27
  description: "display local CLI cache entries",
28
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), show),
28
+ handler: (0, handler_1.createNextHandler)("command.config.cache.show", (0, handler_1.createParseArgumentsHandler)(), show),
29
29
  };
30
30
  exports.default = showCommand;
@@ -48,7 +48,7 @@ const addCommands = async (program) => {
48
48
  command: "set",
49
49
  description: "set global host",
50
50
  args: [{ argument: "host", description: "global host" }],
51
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)([{ argument: "host" }]), set),
51
+ handler: (0, handler_1.createNextHandler)("command.config.host.set", (0, handler_1.createParseArgumentsHandler)([{ argument: "host" }]), set),
52
52
  },
53
53
  {
54
54
  type: "command",
@@ -16,7 +16,7 @@ const passcodeCommand = {
16
16
  type: "command",
17
17
  command: "passcode-url",
18
18
  description: "display the passcode url",
19
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), passcode),
19
+ handler: (0, handler_1.createNextHandler)("commands.config.passcode-url", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), passcode),
20
20
  };
21
21
  const addCommands = async (program) => {
22
22
  if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
@@ -12,6 +12,6 @@ const resetCommand = {
12
12
  type: "command",
13
13
  command: "reset",
14
14
  description: "remove all locally stored secrets for interactive OAuth authentication",
15
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), removeSecrets),
15
+ handler: (0, handler_1.createNextHandler)("commands.config.secrets.reset", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), removeSecrets),
16
16
  };
17
17
  exports.default = resetCommand;
@@ -27,6 +27,6 @@ const showCommand = {
27
27
  type: "command",
28
28
  command: "show",
29
29
  description: "display locally stored secrets for interactive OAuth authentication",
30
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), showSecrets),
30
+ handler: (0, handler_1.createNextHandler)("commands.config.secrets.show", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createResilientHandler)((0, cache_1.create)()), showSecrets),
31
31
  };
32
32
  exports.default = showCommand;
@@ -16,6 +16,6 @@ const core_1 = require("../../../config/core");
16
16
  const succeed_1 = require("../succeed");
17
17
  exports.create = process.env.SUPPORT === "true"
18
18
  ? technicalJWT_1.create
19
- : () => (0, next_1.create)((0, resilient_1.create)((0, next_1.create)((0, cache_1.create)(), (0, refreshToken_1.create)())), (0, options_1.create)(constants_1.OPTION_CLIENT_ID), (0, options_1.create)(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, options_1.create)(constants_1.OPTION_REFRESH_TOKEN), (0, options_1.create)(constants_1.OPTION_CODE), (0, options_1.create)(constants_1.OPTION_TOKEN_URL), (0, options_1.create)(constants_1.OPTION_AUTHORIZATION_URL), (0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)
19
+ : () => (0, next_1.create)("commands.handler.authentication", (0, resilient_1.create)((0, next_1.create)("commands.handler.authentication$oauth", (0, cache_1.create)(), (0, refreshToken_1.create)())), (0, options_1.create)(constants_1.OPTION_CLIENT_ID), (0, options_1.create)(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, options_1.create)(constants_1.OPTION_REFRESH_TOKEN), (0, options_1.create)(constants_1.OPTION_CODE), (0, options_1.create)(constants_1.OPTION_TOKEN_URL), (0, options_1.create)(constants_1.OPTION_AUTHORIZATION_URL), (0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)
20
20
  ? (0, options_1.create)(constants_1.OPTION_PASSCODE)
21
- : (0, succeed_1.create)(), (0, options_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)((0, setAuthorization_1.create)(), (0, passcode_1.create)(), (0, oauth_1.create)()));
21
+ : (0, succeed_1.create)(), (0, options_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)("commands.handler.authentication$handler", (0, setAuthorization_1.create)(), (0, passcode_1.create)(), (0, oauth_1.create)()));
@@ -11,7 +11,7 @@ const constants_1 = require("../../../../constants");
11
11
  const core_1 = require("../../../../config/core");
12
12
  const create = () => {
13
13
  if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.oauth)) {
14
- return (0, error_1.create)("failed to handle OAuth authorization", (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_PASSCODE), (0, secretsProvider_1.create)(), (0, tokenProvider_1.create)()));
14
+ return (0, error_1.create)("failed to handle OAuth authorization", (0, next_1.create)("commands.handler.authentication.oauth", (0, checkOptionsExistence_1.create)(constants_1.OPTION_PASSCODE), (0, secretsProvider_1.create)(), (0, tokenProvider_1.create)()));
15
15
  }
16
16
  return (0, fail_1.create)();
17
17
  };
@@ -21,5 +21,5 @@ const handler = async () => async () => {
21
21
  throw err;
22
22
  }
23
23
  };
24
- const create = () => (0, next_1.create)((0, options_2.create)([constants_1.OPTION_SECRETS_FILE]), handler);
24
+ const create = () => (0, next_1.create)("commands.handler.authentication.oauth.secretsProvider.file", (0, options_2.create)([constants_1.OPTION_SECRETS_FILE]), handler);
25
25
  exports.create = create;
@@ -6,5 +6,5 @@ const error_1 = require("../../../error");
6
6
  const options_1 = require("./options");
7
7
  const file_1 = require("./file");
8
8
  const cache_1 = require("./cache");
9
- const create = () => (0, error_1.create)("Failed to read secrets from cache, file or options", (0, or_1.create)((0, cache_1.create)(), (0, file_1.create)(), (0, options_1.create)()));
9
+ const create = () => (0, error_1.create)("Failed to read secrets from cache, file or options", (0, or_1.create)("commands.handler.authentication.oauth.secretsProvider", (0, cache_1.create)(), (0, file_1.create)(), (0, options_1.create)()));
10
10
  exports.create = create;
@@ -27,7 +27,7 @@ const pre = async () => async () => {
27
27
  const { info } = getLogger();
28
28
  info("reading secrets from options");
29
29
  };
30
- const create = () => (0, next_1.create)(pre, (0, or_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN, false), (0, next_1.create)(createOptHandler(constants_1.OPTION_CLIENT_ID), createOptHandler(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)([
30
+ const create = () => (0, next_1.create)("handler.authentication.oauth.secretsProvider.options$outer", pre, (0, or_1.create)("commands.handler.authentication.oauth.secretsProvider.options", (0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN, false), (0, next_1.create)("handler.authentication.oauth.secretsProvider.options$inner", createOptHandler(constants_1.OPTION_CLIENT_ID), createOptHandler(constants_1.OPTION_CLIENT_SECRET), (0, options_1.create)([
31
31
  constants_1.OPTION_AUTHORIZATION_URL,
32
32
  constants_1.OPTION_TOKEN_URL,
33
33
  constants_1.OPTION_REFRESH_TOKEN,
@@ -28,5 +28,5 @@ const handler = async () => async () => {
28
28
  throw new Error("access token not available");
29
29
  }
30
30
  };
31
- const create = () => (0, next_1.create)((0, options_1.create)(constants_1.OPTION_CODE), handler);
31
+ const create = () => (0, next_1.create)("commands.handler.authentication.oauth.tokenProvider.getToken", (0, options_1.create)(constants_1.OPTION_CODE), handler);
32
32
  exports.create = create;
@@ -7,5 +7,5 @@ const or_1 = require("../../../or");
7
7
  const refreshToken_1 = require("./refreshToken");
8
8
  const setAuthorization_1 = require("./setAuthorization");
9
9
  const getToken_1 = require("./getToken");
10
- const create = () => (0, error_1.create)("failed to handle token", (0, next_1.create)((0, or_1.create)((0, getToken_1.create)(), (0, refreshToken_1.create)(true)), (0, setAuthorization_1.create)()));
10
+ const create = () => (0, error_1.create)("failed to handle token", (0, next_1.create)("commands.handler.authentication.oauth.tokenProvider", (0, or_1.create)("commands.handler.authentication.oauth.tokenProvider", (0, getToken_1.create)(), (0, refreshToken_1.create)(true)), (0, setAuthorization_1.create)()));
11
11
  exports.create = create;
@@ -12,7 +12,7 @@ const constants_1 = require("../../../../constants");
12
12
  const core_1 = require("../../../../config/core");
13
13
  const create = () => {
14
14
  if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
15
- return (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_CLIENT_ID), (0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, checkOptionsExistence_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)((0, function_1.create)(), (0, input_1.create)()), (0, setPasscode_1.create)());
15
+ return (0, next_1.create)("commands.handler.authentication.passcode", (0, checkOptionsExistence_1.create)(constants_1.OPTION_CLIENT_ID), (0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, checkOptionsExistence_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)("commands.handler.authentication.passcode$value", (0, function_1.create)(), (0, input_1.create)()), (0, setPasscode_1.create)());
16
16
  }
17
17
  return (0, fail_1.create)();
18
18
  };
@@ -6,7 +6,7 @@ const commands_1 = require("../../../../utils/commands");
6
6
  const types_1 = require("./types");
7
7
  const utils_1 = require("./utils");
8
8
  const create = () => async (command) => {
9
- command.addOption(await (0, commands_1.buildOption)(types_1.OPTION_SECRET));
9
+ command.addOption(await (0, commands_1.buildOption)(command.name(), types_1.OPTION_SECRET));
10
10
  return async () => {
11
11
  const token = await (0, utils_1.getTechnicalJwt)();
12
12
  (0, config_1.set)({ authorization: { Authorization: `Bearer ${token}` } });
@@ -18,7 +18,7 @@ const createCsrfTokenFetchHandler = (path, parameterMappings) => (0, fetch_1.cre
18
18
  const create = (method, path, parameterMappings, responsePostProcessor) => {
19
19
  /* jscpd:ignore-end */
20
20
  if (requiresCsrfToken(parameterMappings)) {
21
- return (0, next_1.create)(createCsrfTokenFetchHandler(path, parameterMappings), (0, fetch_1.create)(method, path, parameterMappings, responsePostProcessor));
21
+ return (0, next_1.create)("commands.handler.fetch", createCsrfTokenFetchHandler(path, parameterMappings), (0, fetch_1.create)(method, path, parameterMappings, responsePostProcessor));
22
22
  }
23
23
  return (0, fetch_1.create)(method, path, parameterMappings, responsePostProcessor);
24
24
  };
@@ -30,5 +30,5 @@ const readBodyFromFile = async () => async () => {
30
30
  throw err;
31
31
  }
32
32
  };
33
- const create = () => (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_INPUT), (0, options_1.create)(constants_1.OPTION_FILE_PATH, { readEnv: true, readFile: true, readOptions: true }, true, true), readBodyFromFile);
33
+ const create = () => (0, next_1.create)("file.input.handler", (0, checkOptionsExistence_1.create)(constants_1.OPTION_INPUT), (0, options_1.create)(constants_1.OPTION_FILE_PATH, { readEnv: true, readFile: true, readOptions: true }, true, true), readBodyFromFile);
34
34
  exports.create = create;
@@ -4,5 +4,5 @@ exports.create = void 0;
4
4
  const or_1 = require("../or");
5
5
  const input_1 = require("./input");
6
6
  const file_1 = require("./file");
7
- const create = () => (0, or_1.create)((0, file_1.create)(), (0, input_1.create)());
7
+ const create = () => (0, or_1.create)("commands.handler.input", (0, file_1.create)(), (0, input_1.create)());
8
8
  exports.create = create;
@@ -10,7 +10,7 @@ const constants_1 = require("../../../constants");
10
10
  const logger_1 = require("../../../logger");
11
11
  const commands_1 = require("../../../utils/commands");
12
12
  const create = () => async (command) => {
13
- command.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_INPUT));
13
+ command.addOption(await (0, commands_1.buildOption)(command.name(), constants_1.OPTION_INPUT));
14
14
  return async () => {
15
15
  const config = (0, config_1.get)();
16
16
  const { debug } = (0, logger_1.get)("handler.input.input");
@@ -21,5 +21,5 @@ const post = async () => async () => {
21
21
  }
22
22
  }
23
23
  };
24
- const create = () => (0, next_1.create)((0, options_1.create)(MANDATORY_OPTIONS), post);
24
+ const create = () => (0, next_1.create)("mandatoryOptions.handler", (0, options_1.create)(MANDATORY_OPTIONS), post);
25
25
  exports.create = create;
@@ -1,2 +1,2 @@
1
1
  import { Handler } from "../../types";
2
- export declare const create: (...handlers: Array<Handler>) => Handler;
2
+ export declare const create: (origin: string, ...handlers: Array<Handler>) => Handler;
@@ -2,19 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = void 0;
4
4
  const stackTrace_1 = require("./stackTrace");
5
- const nextHandler = (...handlers) => async (command) => {
5
+ const logger_1 = require("../../logger");
6
+ function getLogger(origin) {
7
+ return (0, logger_1.get)(`commands.handler.next:${origin}`);
8
+ }
9
+ const nextHandler = (origin, ...handlers) => async (command) => {
10
+ getLogger(origin).trace(`next:${origin}: preparing handlers`);
6
11
  const commandHandlers = [];
7
12
  for (const handler of handlers) {
8
13
  // eslint-disable-next-line no-await-in-loop
9
14
  commandHandlers.push(await handler(command));
10
15
  }
11
16
  return async (...args) => {
17
+ getLogger(origin).trace(`next:${origin}: processing handlers`);
12
18
  for (const handler of commandHandlers) {
13
19
  // eslint-disable-next-line
14
20
  await handler(...args);
15
21
  }
16
22
  };
17
23
  };
18
- const create = (...handlers) => (0, stackTrace_1.create)(nextHandler(...handlers));
24
+ const create = (origin, ...handlers) => (0, stackTrace_1.create)(nextHandler(origin, ...handlers));
19
25
  exports.create = create;
20
26
  /* jscpd:ignore-end */
@@ -11,7 +11,7 @@ const option_1 = require("./option");
11
11
  const succeed_1 = require("../succeed");
12
12
  const fail_1 = require("../fail");
13
13
  const env_1 = require("./env");
14
- const createHandler = (use, option, handler) => (0, next_1.create)((0, checkOptionsExistence_1.create)(option), use ? handler : (0, succeed_1.create)());
14
+ const createHandler = (use, option, handler) => (0, next_1.create)("commands.handler.options", (0, checkOptionsExistence_1.create)(option), use ? handler : (0, succeed_1.create)());
15
15
  const create = (options, { readEnv, readFile, readOptions } = {
16
16
  readEnv: true,
17
17
  readFile: true,
@@ -21,7 +21,7 @@ const create = (options, { readEnv, readFile, readOptions } = {
21
21
  await (0, utils_1.checkOptions)(intOptions, command);
22
22
  return async () => {
23
23
  for (const option of intOptions) {
24
- const handler = (0, or_1.create)((0, checkOptionsExistence_1.create)(option, false), (0, or_1.create)(createHandler(readEnv, option, (0, env_1.create)(option)), createHandler(readFile, option, (0, file_1.create)(option)), createHandler(readOptions, option, (0, option_1.create)(option, promptAlways))), throwIfHandlersFailed
24
+ const handler = (0, or_1.create)("commands.handler.options$outer", (0, checkOptionsExistence_1.create)(option, false), (0, or_1.create)("commands.handler.options$inner", createHandler(readEnv, option, (0, env_1.create)(option)), createHandler(readFile, option, (0, file_1.create)(option)), createHandler(readOptions, option, (0, option_1.create)(option, promptAlways))), throwIfHandlersFailed
25
25
  ? (0, fail_1.create)()
26
26
  : (0, succeed_1.create)());
27
27
  await (await handler(command))();
@@ -13,8 +13,9 @@ const checkOptions = async (options, command) => {
13
13
  const intOptions = Array.isArray(options) ? options : [options];
14
14
  for (const option of intOptions) {
15
15
  if (!(0, commands_1.isOptionAlreadyRegistered)(option, command)) {
16
+ command.addOption(
16
17
  // eslint-disable-next-line no-await-in-loop
17
- command.addOption(await (0, commands_1.buildOption)({ ...option, required: false }));
18
+ await (0, commands_1.buildOption)(command.name(), { ...option, required: false }));
18
19
  }
19
20
  }
20
21
  };
@@ -1,2 +1,2 @@
1
1
  import { Handler } from "../../types";
2
- export declare const create: (...handlers: Array<Handler>) => Handler;
2
+ export declare const create: (origin: string, ...handlers: Array<Handler>) => Handler;
@@ -2,17 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = void 0;
4
4
  const logger_1 = require("../../logger");
5
- const getLogger = () => (0, logger_1.get)("commands.handlers.or");
6
- const create = (...handlers) => {
5
+ function getLogger(origin) {
6
+ return (0, logger_1.get)(`commands.handler.or:${origin}`);
7
+ }
8
+ const create = (origin, ...handlers) => {
7
9
  const { stack } = new Error();
8
10
  return async (command) => {
11
+ const { trace } = getLogger(origin);
12
+ trace(`or:${origin}: preparing handlers`);
9
13
  const commandHandlers = [];
10
14
  for (const handler of handlers) {
11
15
  // eslint-disable-next-line no-await-in-loop
12
16
  commandHandlers.push(await handler(command));
13
17
  }
14
18
  return async (...args) => {
15
- const { debug, trace } = getLogger();
19
+ const { debug } = getLogger(origin);
20
+ trace(`or:${origin}: processing handlers`);
16
21
  let handlerFailed = false;
17
22
  for (const handler of commandHandlers) {
18
23
  handlerFailed = false;
@@ -1,5 +1,6 @@
1
1
  import { AuthenticationMethod } from "../../constants";
2
2
  export declare const getBooleanOption: (value: unknown) => boolean;
3
+ export declare const replaceLeadingTrailingSingleQuotes: (value: string) => string;
3
4
  export declare const parseOption: (value: string) => string;
4
5
  export declare const setAuthenticationMethod: (authenticationMethod: AuthenticationMethod) => void;
5
6
  export declare const getAuthenticationMethod: () => AuthenticationMethod;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTargetHost = exports.setTargetHost = exports.getAuthenticationMethod = exports.setAuthenticationMethod = exports.parseOption = exports.getBooleanOption = void 0;
3
+ exports.getTargetHost = exports.setTargetHost = exports.getAuthenticationMethod = exports.setAuthenticationMethod = exports.parseOption = exports.replaceLeadingTrailingSingleQuotes = exports.getBooleanOption = void 0;
4
4
  const logger_1 = require("../../logger");
5
5
  const config_1 = require("../../config");
6
6
  const constants_1 = require("../../constants");
@@ -24,13 +24,14 @@ const replaceLeadingTrailingSingleQuotes = (value) => {
24
24
  }
25
25
  return value;
26
26
  };
27
+ exports.replaceLeadingTrailingSingleQuotes = replaceLeadingTrailingSingleQuotes;
27
28
  const parseOption = (value) => {
28
29
  if (typeof value !== "string") {
29
30
  return value;
30
31
  }
31
32
  let v = value.trim();
32
33
  v = decodeURIComponentInt(v);
33
- v = replaceLeadingTrailingSingleQuotes(v);
34
+ v = (0, exports.replaceLeadingTrailingSingleQuotes)(v);
34
35
  return v;
35
36
  };
36
37
  exports.parseOption = parseOption;
@@ -1,3 +1,4 @@
1
- import { LeafCommand } from "../types";
1
+ import { CommanderHandler, LeafCommand } from "../types";
2
+ export declare const verifyHost: () => Promise<CommanderHandler>;
2
3
  declare const loginCommand: LeafCommand;
3
4
  export default loginCommand;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyHost = void 0;
3
4
  const handler_1 = require("./handler");
4
5
  const constants_1 = require("../constants");
5
6
  const logger_1 = require("../logger");
@@ -23,6 +24,7 @@ const verifyHost = async () => async () => {
23
24
  throw new Error("tenant URL not defined. use option -H, --host");
24
25
  }
25
26
  };
27
+ exports.verifyHost = verifyHost;
26
28
  const initializeCache = async () => async () => {
27
29
  const { warn, info } = getLogger();
28
30
  info("initializing cache after successful login");
@@ -31,7 +33,7 @@ const initializeCache = async () => async () => {
31
33
  await (await (0, init_command_1.init)())();
32
34
  }
33
35
  catch (err) {
34
- warn(`option ${(0, utils_3.buildOptionName)(constants_1.OPTION_HOST)} not defined, skipping cache init`);
36
+ warn(`option ${(0, utils_3.buildOptionName)(constants_1.ROOT_COMMAND_NAME, constants_1.OPTION_HOST)} not defined, skipping cache init`);
35
37
  }
36
38
  };
37
39
  const loginCommand = {
@@ -39,7 +41,7 @@ const loginCommand = {
39
41
  command: "login",
40
42
  description: "log in to your account using interactive OAuth authentication",
41
43
  options: [],
42
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
44
+ handler: (0, handler_1.createNextHandler)("login.command", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
43
45
  { ...constants_1.OPTION_HOST, hidden: false, required: true },
44
46
  constants_1.OPTION_VERBOSE,
45
47
  constants_1.OPTION_OPTIONS_FILE,
@@ -56,6 +58,6 @@ const loginCommand = {
56
58
  choices: utils_4.getBrowserChoices,
57
59
  default: openUtils_1.getDefaultBrowser,
58
60
  },
59
- ]), (0, handler_1.createMandatoryOptionsHandler)(), verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
61
+ ]), (0, handler_1.createMandatoryOptionsHandler)(), exports.verifyHost, (0, handler_1.createOauthHandler)(), initializeCache),
60
62
  };
61
63
  exports.default = loginCommand;
@@ -22,7 +22,7 @@ const logoutCommand = {
22
22
  type: "command",
23
23
  command: "logout",
24
24
  description: "log out from your account",
25
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
25
+ handler: (0, handler_1.createNextHandler)("logout.command", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createOptionsHandler)([
26
26
  { ...constants_1.OPTION_LOGIN_ID, choices: utils_2.getChoices },
27
27
  constants_1.OPTION_VERBOSE,
28
28
  ]), handler),
@@ -45,7 +45,7 @@ const addCommandToArray = (document, commands, segments, index) => {
45
45
  };
46
46
  const setHandler = (command, method, path, parameterMappings, readPathResponseHandler, ...handler) => {
47
47
  // eslint-disable-next-line
48
- command.handler = (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), ...handler, (0, handler_1.createFetchHandler)(method, path, parameterMappings, readPathResponseHandler));
48
+ command.handler = (0, handler_1.createNextHandler)("openAPI.command", (0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), ...handler, (0, handler_1.createFetchHandler)(method, path, parameterMappings, readPathResponseHandler));
49
49
  };
50
50
  const addCommands = async (program) => {
51
51
  const { error, debug, trace } = getLogger();
package/constants.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare enum AuthenticationMethod {
17
17
  oauth = "oauth",
18
18
  passcode = "passcode"
19
19
  }
20
+ export declare const ROOT_COMMAND_NAME = "ROOT";
20
21
  export declare const CLI_NAME = "cli-name";
21
22
  export declare const CLI_PACKAGE_NAME = "cli-package-name";
22
23
  export declare const CLI_DESCRIPTION = "cli-description";
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.CLI_DISCOVERY_PATHS = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
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,6 +13,7 @@ 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";
@@ -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/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,7 +73,7 @@ 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
+ const host = (0, utils_3.replaceLeadingTrailingSingleQuotes)(await func());
76
77
  (0, config_1.set)({
77
78
  tenant: host,
78
79
  options: { ...config.options, [constants_1.OPTION_HOST.longName]: host },
@@ -99,7 +100,7 @@ const initCacheTolerant = async () => {
99
100
  }
100
101
  };
101
102
  const registerMandatoryOptions = () => {
102
- MANDATORY_OPTIONS.forEach((option) => (0, commands_1.registerLongName)(option.longName));
103
+ MANDATORY_OPTIONS.forEach((option) => (0, commands_1.registerLongName)(constants_1.ROOT_COMMAND_NAME, option));
103
104
  };
104
105
  async function setupSecretsStorage() {
105
106
  const instance = new SecretsStorageImpl_1.SecretsStorageImpl();
@@ -128,8 +129,8 @@ const init = async () => {
128
129
  ` config host set "<Server_URL>". Did you initialize the CLI by running ${cliName} config` +
129
130
  ` cache init --host "<Server_URL>"?` +
130
131
  ` Add option --help, -h or go to ${(0, config_1.get)()[constants_1.CLI_SAP_HELP]} for additional information.`);
131
- program.addOption(await (0, commands_1.buildOption)(constants_1.OPTION_HOST));
132
- 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));
133
134
  program.configureHelp({ sortSubcommands: true });
134
135
  program.addHelpText("afterAll", `Only command-specific options are listed here. To learn more about available generic options,` +
135
136
  ` visit ${(0, core_1.getGenericOptionsHelp)()}`);
@@ -139,7 +140,7 @@ const init = async () => {
139
140
  };
140
141
  exports.init = init;
141
142
  const executeCommand = async (command) => {
142
- await program.parseAsync(command?.split(" ") || undefined);
143
+ await program.parseAsync(command?.split(" ") ?? undefined);
143
144
  };
144
145
  exports.executeCommand = executeCommand;
145
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: ({ longName }: Option) => string;
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 = ({ longName }) => {
73
- const shortFlag = (0, commands_1.getShortFlagForLongName)(longName);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cli-core",
3
- "version": "2024.4.0",
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",
@@ -18,11 +18,11 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "ajv": "8.12.0",
21
- "axios": "1.6.5",
21
+ "axios": "1.6.7",
22
22
  "commander": "11.1.0",
23
23
  "compare-versions": "6.1.0",
24
24
  "config": "3.3.10",
25
- "dotenv": "16.3.1",
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;
@@ -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 const getShortFlagForLongName: (longName: string) => string;
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: (longName: string) => string;
7
- export declare const buildOption: ({ longName, description, choices, required, default: defaultValue, args, hidden, }: OptionType) => Promise<Option>;
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
- const getShortFlagForLongName = (longName) => {
38
- for (const s of Object.keys(registeredOptions)) {
39
- if (registeredOptions[s] === longName) {
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 = (longName) => {
56
+ const registerLongName = (commandName, option) => {
57
+ const cName = getCommandNameForShortFlag(commandName, option);
52
58
  try {
53
- return (0, exports.getShortFlagForLongName)(longName);
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[c] = longName;
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 ({ longName, description, choices, required, default: defaultValue, args, hidden, }) => {
73
- const mandatory = !!required;
74
- const shortFlag = (0, exports.registerLongName)(longName);
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 option = new commander_1.Option(`-${shortFlag}, --${longName}${argStr}`, newDescr)
89
+ const cOption = new commander_1.Option(`-${shortFlag}, --${option.longName}${argStr}`, newDescr)
83
90
  .makeOptionMandatory(mandatory)
84
- .hideHelp(!!hidden);
85
- if (defaultValue) {
86
- const defaultStr = typeof defaultValue === "function" ? await defaultValue() : defaultValue;
87
- option.default(defaultStr);
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 = typeof choices === "function" ? await choices() : choices;
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
- option.choices(choicesArr);
106
+ cOption.choices(choicesArr);
95
107
  }
96
- return option;
108
+ return cOption;
97
109
  };
98
110
  exports.buildOption = buildOption;
99
111
  const buildCommand = async (topCommand, command) => {
@@ -106,7 +118,7 @@ const buildCommand = async (topCommand, command) => {
106
118
  comm.enablePositionalOptions();
107
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.longName);
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;