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,34 +92,35 @@ export default class CommandLine {
|
||||
|
||||
static {
|
||||
CommandLine._program.version(PackageJson.version);
|
||||
CommandLine._setupProgramOptions();
|
||||
}
|
||||
|
||||
private static _setupProgramOptions(): void {
|
||||
const handleArrayOption = (value: string, previousValue: string[]) => {
|
||||
if (previousValue) {
|
||||
return previousValue.concat(value);
|
||||
}
|
||||
|
||||
return [value];
|
||||
};
|
||||
|
||||
// Required options
|
||||
CommandLine._program.requiredOption('--application-id <applicationId>', 'The application ID to use');
|
||||
CommandLine._program.requiredOption('--secret <secret>', 'The secret to use');
|
||||
CommandLine._program.requiredOption('--pcast-uri <pcastUri>', 'The pcast URI to use');
|
||||
CommandLine._program.requiredOption('--channel-uri <channelUri>', 'The channel URI to use');
|
||||
const setupProgramOptions = (): void => {
|
||||
const handleArrayOption = (value: string, previousValue: string[]) => {
|
||||
if (previousValue) {
|
||||
return previousValue.concat(value);
|
||||
}
|
||||
|
||||
return [value];
|
||||
};
|
||||
|
||||
// Required options
|
||||
CommandLine._program.requiredOption('--application-id <applicationId>', 'The application ID to use');
|
||||
CommandLine._program.requiredOption('--secret <secret>', 'The secret to use');
|
||||
CommandLine._program.requiredOption('--pcast-uri <pcastUri>', 'The pcast URI to use');
|
||||
CommandLine._program.requiredOption('--channel-uri <channelUri>', 'The channel URI to use');
|
||||
|
||||
CommandLine._program.option('--ingest-uri <ingestUri>', 'The ingest URI to use');
|
||||
CommandLine._program.option('--publisher-uri <publisherUri>', 'The publisher URI to use');
|
||||
CommandLine._program.option('--viewer <browser@version:OS@OSVersion...>', 'The browser and OS for simulating a viewer to use', handleArrayOption, defaultViewers);
|
||||
CommandLine._program.option('--publisher <browser@version:OS@OSVersion...>', 'The browser and OS for simulating a publisher to use', handleArrayOption, defaultPublishers);
|
||||
CommandLine._program.option('-t, --test <test...>', 'The test to run', handleArrayOption, defaultTests);
|
||||
CommandLine._program.option('--use-browserstack', 'Run tests using BrowserStack', defaultUseBrowserstack);
|
||||
CommandLine._program.option('--use-browserstack-local', 'Run tests using BrowserStack Local', defaultUseBrowserstackLocal);
|
||||
CommandLine._program.option('--browserstack-user <username>', 'The BrowserStack username to use', process.env.BROWSERSTACK_USER || '');
|
||||
CommandLine._program.option('--browserstack-key <key>', 'The BrowserStack key to use', process.env.BROWSERSTACK_KEY || '');
|
||||
CommandLine._program.option('--log-level <logLevel>', 'The log level to use', LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(defaultLogLevel));
|
||||
}
|
||||
|
||||
CommandLine._program.option('--ingest-uri <ingestUri>', 'The ingest URI to use');
|
||||
CommandLine._program.option('--publisher-uri <publisherUri>', 'The publisher URI to use');
|
||||
CommandLine._program.option('--viewer <browser@version:OS@OSVersion...>', 'The browser and OS for simulating a viewer to use', handleArrayOption, defaultViewers);
|
||||
CommandLine._program.option('--publisher <browser@version:OS@OSVersion...>', 'The browser and OS for simulating a publisher to use', handleArrayOption, defaultPublishers);
|
||||
CommandLine._program.option('-t, --test <test...>', 'The test to run', handleArrayOption, defaultTests);
|
||||
CommandLine._program.option('--use-browserstack', 'Run tests using BrowserStack', defaultUseBrowserstack);
|
||||
CommandLine._program.option('--use-browserstack-local', 'Run tests using BrowserStack Local', defaultUseBrowserstackLocal);
|
||||
CommandLine._program.option('--browserstack-user <username>', 'The BrowserStack username to use', process.env.BROWSERSTACK_USER || '');
|
||||
CommandLine._program.option('--browserstack-key <key>', 'The BrowserStack key to use', process.env.BROWSERSTACK_KEY || '');
|
||||
CommandLine._program.option('--log-level <logLevel>', 'The log level to use', LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(defaultLogLevel));
|
||||
setupProgramOptions();
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
|
||||
@@ -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