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;
|
||||
}
|
||||
|
||||
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 defaultViewers: string[] = [];
|
||||
const defaultPublishers: string[] = [];
|
||||
@@ -55,7 +38,7 @@ export default class CommandLine {
|
||||
/**
|
||||
* Converts a configuration object to command line arguments array
|
||||
*/
|
||||
public static configToArgs(config: ConfigurationObject): string[] {
|
||||
public static configToArgs(config: CommandLineOptions): string[] {
|
||||
const args: string[] = [];
|
||||
|
||||
// Required options
|
||||
@@ -109,10 +92,8 @@ export default class CommandLine {
|
||||
|
||||
static {
|
||||
CommandLine._program.version(PackageJson.version);
|
||||
CommandLine._setupProgramOptions();
|
||||
}
|
||||
|
||||
private static _setupProgramOptions(): void {
|
||||
const setupProgramOptions = (): void => {
|
||||
const handleArrayOption = (value: string, previousValue: string[]) => {
|
||||
if (previousValue) {
|
||||
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));
|
||||
}
|
||||
|
||||
setupProgramOptions();
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
throw new Error('[CommandLine] is a static class that may not be instantiated');
|
||||
}
|
||||
|
||||
@@ -21,10 +21,9 @@ export default class LoggerFactory {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static setLoggingLevel(level: LoggingLevelType): void {
|
||||
const loggingLevel = LoggingLevelMapping.convertLoggingLevelTypeToLoggingLevel(level);
|
||||
console.log(`${new Date().toISOString()} [LoggerFactory] Setting logging level to [${level}]`);
|
||||
LoggerFactory._threshold.level = loggingLevel;
|
||||
public static setLoggingLevel(level: LoggingLevel): void {
|
||||
console.log(`${new Date().toISOString()} [LoggerFactory] Setting logging level to [${LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(level)}]`);
|
||||
LoggerFactory._threshold.level = level;
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
|
||||
Reference in New Issue
Block a user