* Further refined `CommandLine` class to ensure consistent use of `CommandLineOptions`. * Improved method organization in command line option setup for better readability. * Updated `LoggerFactory` to utilize `LoggingLevel` directly in logging level management, streamlining the process.
75 lines
3.2 KiB
TypeScript
75 lines
3.2 KiB
TypeScript
import {Command} from 'commander';
|
|
import PackageJson from '../../package.json' assert {type: 'json'};
|
|
import {LoggingLevel, LoggingLevelMapping} from '../logger/LoggingLevel';
|
|
|
|
export interface CommandLineOptions {
|
|
applicationId: string;
|
|
secret: string;
|
|
logLevel: LoggingLevel;
|
|
pcastUri: string;
|
|
ingestUri: string;
|
|
channelUri: string;
|
|
publisherUri: string;
|
|
viewers: string[];
|
|
publishers: string[];
|
|
tests: string[];
|
|
useBrowserstack: boolean;
|
|
useBrowserstackLocal: boolean;
|
|
browserstackUser: string;
|
|
browserstackKey: string;
|
|
}
|
|
|
|
const defaultLogLevel = LoggingLevel.Info;
|
|
const defaultViewers: string[] = [];
|
|
const defaultPublishers: string[] = [];
|
|
const defaultTests: string[] = [];
|
|
const defaultUseBrowserstack = false;
|
|
const defaultUseBrowserstackLocal = false;
|
|
|
|
export default class CommandLine {
|
|
private static readonly _program: Command = new Command();
|
|
|
|
public static parse(args: string[]): CommandLineOptions {
|
|
CommandLine._program.parse(args);
|
|
|
|
return CommandLine._program.opts<CommandLineOptions>();
|
|
}
|
|
|
|
static {
|
|
CommandLine._program.version(PackageJson.version);
|
|
|
|
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));
|
|
}
|
|
|
|
setupProgramOptions();
|
|
}
|
|
|
|
private constructor() {
|
|
throw new Error('[CommandLine] is a static class that may not be instantiated');
|
|
}
|
|
}
|