@milkmaccya2/hostswitch
Version:
A simple CLI tool to manage and switch between multiple hosts file profiles for different development environments
62 lines • 2.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CliController = void 0;
const CreateProfileCommand_1 = require("./commands/CreateProfileCommand");
const DeleteProfileCommand_1 = require("./commands/DeleteProfileCommand");
const EditProfileCommand_1 = require("./commands/EditProfileCommand");
const ListProfilesCommand_1 = require("./commands/ListProfilesCommand");
const ShowProfileCommand_1 = require("./commands/ShowProfileCommand");
const SwitchProfileCommand_1 = require("./commands/SwitchProfileCommand");
class CliController {
facade;
ui;
constructor(facade, ui) {
this.facade = facade;
this.ui = ui;
}
async executeCommand(commandType, params = {}) {
try {
const command = this.createCommand(commandType, params);
const result = await command.execute();
await this.ui.handleCommandResult(result);
}
catch (error) {
this.ui.showMessage(`Error executing command: ${error instanceof Error ? error.message : String(error)}`, 'error');
}
}
createCommand(type, params) {
switch (type) {
case 'list':
return new ListProfilesCommand_1.ListProfilesCommand(this.facade);
case 'create':
if (!params.name) {
throw new Error('Profile name is required for create command');
}
return new CreateProfileCommand_1.CreateProfileCommand(this.facade, params.name, params.fromCurrent || false);
case 'switch':
if (!params.name) {
throw new Error('Profile name is required for switch command');
}
return new SwitchProfileCommand_1.SwitchProfileCommand(this.facade, params.name);
case 'edit':
if (!params.name) {
throw new Error('Profile name is required for edit command');
}
return new EditProfileCommand_1.EditProfileCommand(this.facade, params.name);
case 'show':
if (!params.name) {
throw new Error('Profile name is required for show command');
}
return new ShowProfileCommand_1.ShowProfileCommand(this.facade, params.name);
case 'delete':
if (!params.name) {
throw new Error('Profile name is required for delete command');
}
return new DeleteProfileCommand_1.DeleteProfileCommand(this.facade, params.name, params.force || false);
default:
throw new Error(`Unknown command type: ${type}`);
}
}
}
exports.CliController = CliController;
//# sourceMappingURL=CliController.js.map