tdpw
Version:
CLI tool for uploading Playwright test reports to TestDino platform with Azure storage support
140 lines • 4.91 kB
JavaScript
;
/**
* TestDino CLI Entry Point
* Main entry point for the tdpw CLI tool
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestDinoCLI = void 0;
exports.main = main;
const parser_1 = require("./parser");
const upload_1 = require("./commands/upload");
const help_1 = require("./commands/help");
const types_1 = require("../types");
/**
* CLI Application main class
*/
class TestDinoCLI {
uploadCommand;
helpCommand;
constructor() {
this.uploadCommand = new upload_1.UploadCommand();
this.helpCommand = new help_1.HelpCommand();
}
/**
* Main application entry point
*/
async run(args = process.argv) {
try {
// Handle help and version flags before parsing full options
if (this.shouldShowHelp(args)) {
await this.helpCommand.execute({});
process.exit(types_1.ExitCode.SUCCESS);
}
if (this.shouldShowVersion(args)) {
console.log(`tdpw v${parser_1.cliParser.getVersion()}`);
process.exit(types_1.ExitCode.SUCCESS);
}
// Parse CLI arguments
const options = parser_1.cliParser.parseWithErrorHandling(args);
// Execute upload command
await this.uploadCommand.execute(options);
process.exit(types_1.ExitCode.SUCCESS);
}
catch (error) {
await this.handleError(error);
}
}
/**
* Check if help should be displayed
*/
shouldShowHelp(args) {
return args.includes('--help') || args.includes('-h') || args.includes('help');
}
/**
* Check if version should be displayed
*/
shouldShowVersion(args) {
return args.includes('--version') || args.includes('-V');
}
/**
* Professional error handling with appropriate messaging
*/
async handleError(error) {
const isVerbose = process.argv.includes('--verbose') || process.argv.includes('-v');
if (error instanceof types_1.BaseError) {
console.error(`❌ ${error.message}`);
// Show helpful suggestions without being verbose
switch (true) {
case error instanceof types_1.ConfigurationError:
console.error('💡 Check your API token and configuration');
break;
case error instanceof types_1.ValidationError:
console.error('💡 Use --help for correct usage');
break;
case error instanceof types_1.AuthenticationError:
console.error('💡 Verify your API token has proper permissions');
break;
case error instanceof types_1.NetworkError:
console.error('💡 Check your internet connection');
break;
case error instanceof types_1.FileSystemError:
console.error('💡 Verify the specified paths exist and are readable');
break;
}
// Show stack trace only in verbose mode
if (isVerbose && error.stack) {
console.error('\nStack trace:', error.stack);
}
process.exit(this.getExitCode(error));
}
else if (error instanceof Error) {
console.error(`❌ ${error.message}`);
if (!isVerbose) {
console.error('💡 Use --verbose for detailed error information');
}
else if (error.stack) {
console.error('\nStack trace:', error.stack);
}
process.exit(types_1.ExitCode.GENERAL_ERROR);
}
else {
console.error('❌ An unexpected error occurred');
if (isVerbose) {
console.error('Error details:', error);
}
process.exit(types_1.ExitCode.GENERAL_ERROR);
}
}
/**
* Get appropriate exit code for error type
*/
getExitCode(error) {
if (error instanceof types_1.AuthenticationError)
return types_1.ExitCode.AUTHENTICATION_ERROR;
if (error instanceof types_1.NetworkError)
return types_1.ExitCode.NETWORK_ERROR;
if (error instanceof types_1.FileSystemError)
return types_1.ExitCode.FILE_NOT_FOUND_ERROR;
return types_1.ExitCode.GENERAL_ERROR;
}
}
exports.TestDinoCLI = TestDinoCLI;
/**
* Application execution
*/
async function main() {
const cli = new TestDinoCLI();
await cli.run();
}
// Execute CLI when this module is run
(async () => {
try {
await main();
}
catch (error) {
console.error('Fatal error during CLI execution:', error);
process.exit(types_1.ExitCode.GENERAL_ERROR);
}
})();
//# sourceMappingURL=index.js.map