Refactor CommandLine and LoggerFactory for improved type handling
* Updated `CommandLine` class to replace `ConfigurationObject` with `CommandLineOptions` for better type consistency. * Refactored command line option setup into a separate method for clarity. * Modified `LoggerFactory` to directly use `LoggingLevel` type in `setLoggingLevel` method, enhancing logging level management.
This commit is contained in:
@@ -19,23 +19,6 @@ export interface CommandLineOptions {
|
|||||||
browserstackKey: string;
|
browserstackKey: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ConfigurationObject {
|
|
||||||
viewers: string[];
|
|
||||||
publishers: string[];
|
|
||||||
tests: string[];
|
|
||||||
useBrowserstack: boolean;
|
|
||||||
useBrowserstackLocal: boolean;
|
|
||||||
browserstackUser: string;
|
|
||||||
browserstackKey: string;
|
|
||||||
logLevel: LoggingLevel;
|
|
||||||
applicationId: string;
|
|
||||||
secret: string;
|
|
||||||
pcastUri: string;
|
|
||||||
ingestUri: string;
|
|
||||||
channelUri: string;
|
|
||||||
publisherUri?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultLogLevel = LoggingLevel.Info;
|
const defaultLogLevel = LoggingLevel.Info;
|
||||||
const defaultViewers: string[] = [];
|
const defaultViewers: string[] = [];
|
||||||
const defaultPublishers: string[] = [];
|
const defaultPublishers: string[] = [];
|
||||||
@@ -55,7 +38,7 @@ export default class CommandLine {
|
|||||||
/**
|
/**
|
||||||
* Converts a configuration object to command line arguments array
|
* Converts a configuration object to command line arguments array
|
||||||
*/
|
*/
|
||||||
public static configToArgs(config: ConfigurationObject): string[] {
|
public static configToArgs(config: CommandLineOptions): string[] {
|
||||||
const args: string[] = [];
|
const args: string[] = [];
|
||||||
|
|
||||||
// Required options
|
// Required options
|
||||||
@@ -109,10 +92,8 @@ export default class CommandLine {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
CommandLine._program.version(PackageJson.version);
|
CommandLine._program.version(PackageJson.version);
|
||||||
CommandLine._setupProgramOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static _setupProgramOptions(): void {
|
const setupProgramOptions = (): void => {
|
||||||
const handleArrayOption = (value: string, previousValue: string[]) => {
|
const handleArrayOption = (value: string, previousValue: string[]) => {
|
||||||
if (previousValue) {
|
if (previousValue) {
|
||||||
return previousValue.concat(value);
|
return previousValue.concat(value);
|
||||||
@@ -139,6 +120,9 @@ export default class CommandLine {
|
|||||||
CommandLine._program.option('--log-level <logLevel>', 'The log level to use', LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(defaultLogLevel));
|
CommandLine._program.option('--log-level <logLevel>', 'The log level to use', LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(defaultLogLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupProgramOptions();
|
||||||
|
}
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
throw new Error('[CommandLine] is a static class that may not be instantiated');
|
throw new Error('[CommandLine] is a static class that may not be instantiated');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,9 @@ export default class LoggerFactory {
|
|||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static setLoggingLevel(level: LoggingLevelType): void {
|
public static setLoggingLevel(level: LoggingLevel): void {
|
||||||
const loggingLevel = LoggingLevelMapping.convertLoggingLevelTypeToLoggingLevel(level);
|
console.log(`${new Date().toISOString()} [LoggerFactory] Setting logging level to [${LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(level)}]`);
|
||||||
console.log(`${new Date().toISOString()} [LoggerFactory] Setting logging level to [${level}]`);
|
LoggerFactory._threshold.level = level;
|
||||||
LoggerFactory._threshold.level = loggingLevel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
|
|||||||
Reference in New Issue
Block a user