@cqse/commons 0.1.0-beta.8 → 1.0.0-beta.4

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.
@@ -0,0 +1,61 @@
1
+ import { ConfigurationParameters } from './ConfigParser';
2
+ export type PredefinableOptions = {
3
+ keepCoverageFiles: boolean;
4
+ dumpAfterMins: number;
5
+ artifactoryServerUrl?: string;
6
+ artifactoryUser?: string;
7
+ artifactoryPassword?: string;
8
+ artifactoryAccessToken?: string;
9
+ artifactoryPathSuffix?: string;
10
+ };
11
+ /**
12
+ * Options that cannot be reconfigured during runtime.
13
+ * These settings are fixed after initial configuration.
14
+ */
15
+ export type StaticCollectorOptions = PredefinableOptions & {
16
+ port: number;
17
+ dumpFolder: string;
18
+ httpProxy?: string;
19
+ logLevel: string;
20
+ logToFile: string;
21
+ jsonLog: boolean;
22
+ enableControlPort?: number;
23
+ teamscaleServerUrl?: string;
24
+ teamscaleUser?: string;
25
+ teamscaleAccessToken?: string;
26
+ };
27
+ /**
28
+ * Options that can be modified during runtime.
29
+ * These settings control various aspects of the collector's behavior.
30
+ *
31
+ * See the other code in the present file for a list of all available
32
+ * options and their descriptions and default values.
33
+ */
34
+ export type ReconfigurableCollectorOptions = PredefinableOptions & {
35
+ teamscaleProject?: string;
36
+ teamscalePartition?: string;
37
+ teamscaleRepository?: string;
38
+ teamscaleMessage?: string;
39
+ dumpToFolder?: string;
40
+ };
41
+ /**
42
+ * Complete collection of collector configuration options.
43
+ * Combines both fixed and reconfigurable options into a single type.
44
+ */
45
+ export type CollectorOptions = StaticCollectorOptions & ReconfigurableCollectorOptions;
46
+ /**
47
+ * Build the collector parameters that can be overwritten by instrumented apps.
48
+ */
49
+ export declare function buildPredefinableParameters(): ConfigurationParameters;
50
+ /**
51
+ * Builds and returns the configuration parameters for the collector.
52
+ * This includes all available command line arguments and their default values.
53
+ *
54
+ * @returns {ConfigurationParameters} Configuration parameters instance with all defined options
55
+ */
56
+ export declare function buildStaticCollectorParameters(): ConfigurationParameters;
57
+ /**
58
+ * Builds and returns the during run-time reconfigurable configuration parameters for the collector.
59
+ */
60
+ export declare function buildReconfigurableCollectorParameters(): ConfigurationParameters;
61
+ //# sourceMappingURL=CollectorConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CollectorConfig.d.ts","sourceRoot":"","sources":["../src/CollectorConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,uBAAuB,EACvB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,MAAM,mBAAmB,GAAG;IACjC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,8BAA8B,GAAG,mBAAmB,GAAG;IAClE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,GAAG,8BAA8B,CAAC;AAsCvF;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,uBAAuB,CA0CrE;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,IAAI,uBAAuB,CAkDxE;AAED;;GAEG;AACH,wBAAgB,sCAAsC,IAAI,uBAAuB,CAuChF"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPredefinableParameters = buildPredefinableParameters;
4
+ exports.buildStaticCollectorParameters = buildStaticCollectorParameters;
5
+ exports.buildReconfigurableCollectorParameters = buildReconfigurableCollectorParameters;
6
+ const ConfigParser_1 = require("./ConfigParser");
7
+ const CONFIG_GROUP_COLLECTOR_CONNECTIVITY = {
8
+ order: 1,
9
+ title: 'Collector Connectivity'
10
+ };
11
+ const CONFIG_GROUP_TEAMSCALE_SERVER = {
12
+ order: 1,
13
+ title: 'Teamscale Server'
14
+ };
15
+ const CONFIG_GROUP_TEAMSCALE_UPLOAD = {
16
+ order: 2,
17
+ title: 'Upload to Teamscale'
18
+ };
19
+ const CONFIG_GROUP_COVERAGE_DUMP = {
20
+ order: 3,
21
+ title: 'Coverage Dumping'
22
+ };
23
+ const CONFIG_GROUP_ARTIFACTORY_UPLOAD = {
24
+ order: 4,
25
+ title: 'Upload to Artifactory'
26
+ };
27
+ const CONFIG_GROUP_LOGGING = {
28
+ order: 5,
29
+ title: 'Logging Behavior'
30
+ };
31
+ /**
32
+ * Build the collector parameters that can be overwritten by instrumented apps.
33
+ */
34
+ function buildPredefinableParameters() {
35
+ const parameters = new ConfigParser_1.ConfigurationParameters();
36
+ function add(shortParameter, longParameter, type, options) {
37
+ parameters.addParameter(shortParameter, longParameter, type, options);
38
+ }
39
+ add('-k', '--keep-coverage-files', 'bool', {
40
+ help: 'Whether to keep the coverage files on disk after a successful upload to Teamscale.',
41
+ default: false,
42
+ group: CONFIG_GROUP_COVERAGE_DUMP
43
+ });
44
+ add('-t', '--dump-after-mins', 'int', {
45
+ help: 'Dump the coverage information every N minutes.',
46
+ default: 120,
47
+ group: CONFIG_GROUP_COVERAGE_DUMP
48
+ });
49
+ // Artifactory upload
50
+ add(undefined, '--artifactory-server-url', 'string', {
51
+ help: 'Upload the coverage to the given Artifactory server URL. The URL may include a subpath on the artifactory server, e.g. https://artifactory.acme.com/my-repo/my/subpath',
52
+ group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
53
+ });
54
+ add(undefined, '--artifactory-user', 'string', {
55
+ help: 'The user for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option',
56
+ group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
57
+ });
58
+ add(undefined, '--artifactory-password', 'string', {
59
+ help: 'The password for uploading coverage to Artifactory. Only needed when not using the --artifactory-access-token option',
60
+ group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
61
+ });
62
+ add(undefined, '--artifactory-access-token', 'string', {
63
+ help: 'The access_token for uploading coverage to Artifactory.',
64
+ group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
65
+ });
66
+ add(undefined, '--artifactory-path-suffix', 'string', {
67
+ help: '(optional): The path within the storage location between the default path and the uploaded artifact.',
68
+ group: CONFIG_GROUP_ARTIFACTORY_UPLOAD
69
+ });
70
+ return parameters;
71
+ }
72
+ /**
73
+ * Builds and returns the configuration parameters for the collector.
74
+ * This includes all available command line arguments and their default values.
75
+ *
76
+ * @returns {ConfigurationParameters} Configuration parameters instance with all defined options
77
+ */
78
+ function buildStaticCollectorParameters() {
79
+ const parameters = buildPredefinableParameters();
80
+ function add(shortParameter, longParameter, type, options) {
81
+ parameters.addParameter(shortParameter, longParameter, type, options);
82
+ }
83
+ add('-p', '--port', 'int', { help: 'The port to receive coverage information on.',
84
+ default: 54678, group: CONFIG_GROUP_COLLECTOR_CONNECTIVITY, disableEnvironmentVariableOverride: true });
85
+ add('-l', '--log-to-file', 'string', { help: 'Log file', default: 'logs/collector-combined.log', group: CONFIG_GROUP_LOGGING,
86
+ disableEnvironmentVariableOverride: true });
87
+ add('-e', '--log-level', 'string', { help: 'Log level',
88
+ default: 'info', group: CONFIG_GROUP_LOGGING, disableEnvironmentVariableOverride: true });
89
+ add('-j', '--json-log', 'bool', { help: 'Additional JSON-like log file format.',
90
+ group: CONFIG_GROUP_LOGGING, disableEnvironmentVariableOverride: true });
91
+ add('-c', '--enable-control-port', 'int', {
92
+ help: 'Enables the remote control API on the specified port (<=0 means "disabled").',
93
+ default: 0, group: CONFIG_GROUP_COLLECTOR_CONNECTIVITY
94
+ });
95
+ add('-s', '--teamscale-server-url', 'string', {
96
+ help: 'Upload the coverage to the given Teamscale server URL, for example, https://teamscale.dev.example.com:8080/production.',
97
+ group: CONFIG_GROUP_TEAMSCALE_SERVER
98
+ });
99
+ add('-u', '--teamscale-user', 'string', {
100
+ help: 'The user for uploading coverage to Teamscale.',
101
+ group: CONFIG_GROUP_TEAMSCALE_SERVER
102
+ });
103
+ add('-a', '--teamscale-access-token', 'string', {
104
+ help: 'The API key to use for uploading to Teamscale.',
105
+ group: CONFIG_GROUP_TEAMSCALE_SERVER
106
+ });
107
+ add(undefined, '--http-proxy', 'string', {
108
+ help: '(optional): The HTTP/HTTPS proxy address that should be used in the format: http://host:port/ or http://username:password@host:port/.',
109
+ group: CONFIG_GROUP_COLLECTOR_CONNECTIVITY,
110
+ });
111
+ add('-f', '--dump-folder', 'string', {
112
+ help: 'Target folder for coverage files.',
113
+ default: './coverage',
114
+ group: CONFIG_GROUP_COVERAGE_DUMP
115
+ });
116
+ parameters.addArgumentCheck((options) => {
117
+ if (options.teamscaleServerUrl) {
118
+ if (!options.teamscaleUser || !options.teamscaleAccessToken) {
119
+ return 'The Teamscale user name and access token must be given if the Teamscale server URL is given.';
120
+ }
121
+ }
122
+ });
123
+ return parameters;
124
+ }
125
+ /**
126
+ * Builds and returns the during run-time reconfigurable configuration parameters for the collector.
127
+ */
128
+ function buildReconfigurableCollectorParameters() {
129
+ const parameters = buildPredefinableParameters();
130
+ function addShort(shortParameter, longParameter, type, options) {
131
+ parameters.addParameter(shortParameter, longParameter, type, options);
132
+ }
133
+ function add(longArgument, type, options) {
134
+ addShort(undefined, longArgument, type, options);
135
+ }
136
+ // Coverage dumping
137
+ add('--dump-to-folder', 'string', {
138
+ help: 'Coverage should be dumped to a folder on the server that the collector is running on.\n' +
139
+ 'Specifies the name of the subfolder within the collector\'s dump folder (--dump-folder of the collector) where coverage files should be placed.',
140
+ group: CONFIG_GROUP_COVERAGE_DUMP
141
+ });
142
+ // Upload to Teamscale
143
+ add('--teamscale-project', 'string', {
144
+ help: 'The project ID to upload coverage to.',
145
+ group: CONFIG_GROUP_TEAMSCALE_UPLOAD
146
+ });
147
+ add('--teamscale-partition', 'string', {
148
+ help: 'The partition to upload coverage to.',
149
+ group: CONFIG_GROUP_TEAMSCALE_UPLOAD
150
+ });
151
+ add('--teamscale-repository', 'string', {
152
+ help: 'The repository to upload coverage for. Optional: Only needed when uploading via revision to a project that has more than one connector.',
153
+ group: CONFIG_GROUP_TEAMSCALE_UPLOAD
154
+ });
155
+ add('--teamscale-message', 'string', {
156
+ help: 'The commit message shown within Teamscale for the coverage upload.',
157
+ default: 'JavaScript coverage upload',
158
+ group: CONFIG_GROUP_TEAMSCALE_UPLOAD
159
+ });
160
+ return parameters;
161
+ }
162
+ //# sourceMappingURL=CollectorConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CollectorConfig.js","sourceRoot":"","sources":["../src/CollectorConfig.ts"],"names":[],"mappings":";;AA6FA,kEA0CC;AAQD,wEAkDC;AAKD,wFAuCC;AA7OD,iDAGwB;AAyDxB,MAAM,mCAAmC,GAAmB;IAC3D,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,wBAAwB;CAC/B,CAAC;AAEF,MAAM,6BAA6B,GAAmB;IACrD,KA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AAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAgB,sCAAsC;IACrD,MAAM,UAAU,GAAG,2BAA2B,EAAE,CAAC;IAEjD,SAAS,QAAQ,CAAC,cAAkC,EAAE,aAAqB,EAAE,IAAyB,EAChG,OAAwB;QAC7B,UAAU,CAAC,YAAY,CAAC,cAAc,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACtE,CAAC;IAED,SAAS,GAAG,CAAC,YAAoB,EAAE,IAAyB,EAAE,OAAmC;QAChG,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,mBAAmB;IACnB,GAAG,CAAC,kBAAkB,EAAE,QAAQ,EAAE;QACjC,IAAI,EAAE,yFAAyF;YAC9F,iJAAiJ;QAClJ,KAAK,EAAE,0BAA0B;KACjC,CAAC,CAAC;IAEH,sBAAsB;IACtB,GAAG,CAAC,qBAAqB,EAAE,QAAQ,EAAE;QACpC,IAAI,EAAE,uCAAuC;QAC7C,KAAK,EAAE,6BAA6B;KACpC,CAAC,CAAC;IACH,GAAG,CAAC,uBAAuB,EAAE,QAAQ,EAAE;QACtC,IAAI,EAAE,sCAAsC;QAC5C,KAAK,EAAE,6BAA6B;KACpC,CAAC,CAAC;IACH,GAAG,CAAC,wBAAwB,EAAE,QAAQ,EAAE;QACvC,IAAI,EAAE,yIAAyI;QAC/I,KAAK,EAAE,6BAA6B;KACpC,CAAC,CAAC;IACH,GAAG,CAAC,qBAAqB,EAAE,QAAQ,EAAE;QACpC,IAAI,EAAE,oEAAoE;QAC1E,OAAO,EAAE,4BAA4B;QACrC,KAAK,EAAE,6BAA6B;KACpC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Configuration parser module that handles command-line arguments, environment variables,
3
+ * and configuration files for TypeScript/JavaScript applications.
4
+ *
5
+ * @module ConfigParser
6
+ */
7
+ /** Supported parameter types for configuration options */
8
+ export type ConfigParameterType = 'string' | 'int' | 'bool' | 'string[]';
9
+ /** Possible value types for configuration parameters */
10
+ export type ConfigValueType = string | number | boolean | string[];
11
+ /** Record of parameter names to their values */
12
+ export type Options = Record<string, ConfigValueType>;
13
+ /** Options for printing the version and help information */
14
+ export type VersionAndHelpOptions = {
15
+ version: boolean;
16
+ help: boolean;
17
+ };
18
+ /** Result of parsing the configuration containing options and unnamed arguments */
19
+ export type ConfigParsingResult = {
20
+ options: Options;
21
+ unnamedArguments: string[];
22
+ };
23
+ /** Describes the application that is going to be configured and run. */
24
+ export type AppInfos = {
25
+ name: string;
26
+ version: string;
27
+ about: string;
28
+ };
29
+ /** Defines a group of configuration parameters. */
30
+ export type ParameterGroup = {
31
+ /** Number used as the primary criterion for ordering */
32
+ order: number;
33
+ /** Title of the group */
34
+ title: string;
35
+ };
36
+ /** Parameter group for --version and --help */
37
+ export declare const CONFIG_GROUP_APP: ParameterGroup;
38
+ /** Describes a configuration parameter with its properties */
39
+ export type ParameterDescriptor = {
40
+ /** Internal identifier for the parameter */
41
+ parameterId: string;
42
+ /** Short form of the parameter (e.g., -p) */
43
+ shortParameter?: string;
44
+ /** Long form of the parameter (e.g., --port) */
45
+ longParameter: string;
46
+ /** Environment variable name for this parameter */
47
+ environmentVariableName: string;
48
+ /** Disable overwriting the parameter value via an environment variable? */
49
+ disableEnvironmentVariableOverride?: boolean;
50
+ /** Parameter's data type */
51
+ type: ConfigParameterType;
52
+ /** Default value if parameter is not specified */
53
+ default?: ConfigValueType;
54
+ /** Help text describing the parameter */
55
+ help: string;
56
+ /**
57
+ * Is it an internal parameter, not to be visible in the command line by default?
58
+ * An example is a parameter that is configured via a different mechanism but still
59
+ * shall be present in the configuration mechanism at hand.
60
+ */
61
+ internal: boolean;
62
+ /** Parameter group it belongs to. */
63
+ group?: ParameterGroup;
64
+ };
65
+ /**
66
+ * See `ParameterDescriptor`.
67
+ */
68
+ export type ParameterDefinitionOptions = Partial<ParameterDescriptor>;
69
+ /**
70
+ * Converts a parameter name (with dashes) to a camelCase parameter ID.
71
+ *
72
+ * @param parameterName - The parameter name to convert (e.g., --my-param)
73
+ * @returns The camelCase parameter ID (e.g., myParam)
74
+ */
75
+ export declare function parameterNameToParameterId(parameterName: string): string;
76
+ /**
77
+ * Converts a long parameter name to an environment variable name.
78
+ *
79
+ * @param longParameter - The long parameter name (e.g., --my-param)
80
+ * @returns The environment variable name (e.g., MY_PARAM)
81
+ */
82
+ export declare function longParameterToEnvironmentVariableName(longParameter: string): string;
83
+ /**
84
+ * Manages configuration parameters and their properties.
85
+ * Provides functionality to add, describe, and parse parameters.
86
+ */
87
+ export declare class ConfigurationParameters {
88
+ private readonly parameters;
89
+ private readonly shortToLongParameterMap;
90
+ private readonly sequentialParameters;
91
+ private readonly argumentChecks;
92
+ constructor();
93
+ /**
94
+ * Adds a new parameter to the configuration.
95
+ *
96
+ * @param shortParameter - Optional short form of the parameter (e.g., -p)
97
+ * @param longParameter - Long form of the parameter (e.g., --port)
98
+ * @param type - Parameter's data type
99
+ * @param options - Additional parameter options including a help text and default value
100
+ */
101
+ addParameter(shortParameter: string | undefined, longParameter: string, type: ConfigParameterType, options?: ParameterDefinitionOptions): void;
102
+ /**
103
+ * Adds a new argument check function to the list of checks.
104
+ *
105
+ * @param check - A function that takes an options object as input and returns a string containing an
106
+ * error message if a validation fails, or undefined if the validation passes.
107
+ */
108
+ addArgumentCheck(check: (options: Record<string, unknown>) => string | undefined): void;
109
+ /**
110
+ * Makes the given parameter mandatory.
111
+ */
112
+ addRequiredArgumentFor(parameterId: string): void;
113
+ /**
114
+ * Describes a parameter with its complete set of properties.
115
+ *
116
+ * @param parameterId - Internal identifier for the parameter
117
+ * @param descriptor - Complete parameter descriptor
118
+ * @throws Error if short parameter is invalid or already mapped
119
+ */
120
+ describeParameter(parameterId: string, descriptor: ParameterDescriptor): void;
121
+ /**
122
+ * Looks up a parameter descriptor by its ID.
123
+ *
124
+ * @param parameterId - Parameter identifier to look up
125
+ * @returns Parameter descriptor if found, undefined otherwise
126
+ */
127
+ lookupParameter(parameterId: string): ParameterDescriptor | undefined;
128
+ /**
129
+ * Returns all registered parameter descriptors.
130
+ *
131
+ * @returns Array of all parameter descriptors
132
+ */
133
+ getParameters(): ParameterDescriptor[];
134
+ /**
135
+ * Retrieves the collection of functions used for argument validation.
136
+ */
137
+ getArgumentChecks(): Array<(options: Record<string, unknown>) => string | undefined>;
138
+ /**
139
+ * Returns an array of parameter IDs that are configured as sequential parameters.
140
+ * That is, parameters that are given without a name but where their mapping
141
+ * to concrete parameters is defined by their position in the command line.
142
+ */
143
+ getSequentialParameters(): string[];
144
+ /**
145
+ * @returns A new configuration object with the same parameters as this one.
146
+ */
147
+ clone(): ConfigurationParameters;
148
+ /**
149
+ * Adds all parameters and checks from the given configuration to this one.
150
+ */
151
+ addAllOf(toAdd: ConfigurationParameters): void;
152
+ }
153
+ /**
154
+ * Parses command line arguments according to parameter definitions.
155
+ *
156
+ * @param args - Array of command line arguments to parse
157
+ * @param parameters - Configuration parameters defining valid options
158
+ * @returns Parsed options object with parameter values
159
+ * @throws Error if parameter values are invalid or missing
160
+ */
161
+ export declare function parseArguments<OptionsType extends Record<string, unknown>>(args: string[], parameters: ConfigurationParameters): Partial<OptionsType>;
162
+ /**
163
+ * Parses a configuration file content into options and unnamed arguments.
164
+ *
165
+ * @param fileContent - Content of the configuration file to parse
166
+ * @param parameters - Configuration parameters defining valid options
167
+ * @returns Object containing parsed options and unnamed arguments
168
+ * @throws Error if the configuration file contains invalid parameters or values
169
+ */
170
+ export declare function parseConfigFile(fileContent: string, parameters: ConfigurationParameters): ConfigParsingResult;
171
+ /**
172
+ * Prints help information for all registered parameters.
173
+ *
174
+ * @param parameters - Configuration parameters to display help for
175
+ * @param aboutText - Optional descriptive text to display before parameter help
176
+ * @param printParamterId - Print the ID of the parameter instead of the command line parameter names?
177
+ */
178
+ export declare function printHelp(parameters: ConfigurationParameters, aboutText?: string, printParamterId?: boolean): void;
179
+ /**
180
+ * Runs the config parameter checks for the given options.
181
+ */
182
+ export declare function checkArguments(configParameters: ConfigurationParameters, options: Options, errorReceiver?: (error: string) => void): boolean;
183
+ /**
184
+ * Parses the command-line arguments.
185
+ */
186
+ export declare function processCommandLine<O>(parameters: ConfigurationParameters, appInfos: AppInfos, args?: string[], beforeCheckCallback?: (options: O) => void): O;
187
+ /**
188
+ * Creates a new configuration object by merging two configuration objects.
189
+ */
190
+ export declare function parameterUnion(parameters1: ConfigurationParameters, parameters2: ConfigurationParameters): ConfigurationParameters;
191
+ //# sourceMappingURL=ConfigParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigParser.d.ts","sourceRoot":"","sources":["../src/ConfigParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,0DAA0D;AAC1D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAEzE,wDAAwD;AACxD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC;AAEnE,gDAAgD;AAChD,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEtD,4DAA4D;AAC5D,MAAM,MAAM,qBAAqB,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAExE,mFAAmF;AACnF,MAAM,MAAM,mBAAmB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACd,CAAA;AAED,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG;IAC5B,wDAAwD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