UNPKG

gcal-commander

Version:

A command-line interface for Google Calendar operations

57 lines (56 loc) 2.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const base_command_1 = require("../base-command"); const languages_1 = require("../constants/languages"); const tokens_1 = require("../di/tokens"); class Init extends base_command_1.BaseCommand { static description = 'Verify Google Calendar authentication setup'; static examples = ['<%= config.bin %> <%= command.id %>']; promptService; async init() { await super.init(); this.promptService = this.getContainer().resolve(tokens_1.TOKENS.PromptService); this.calendarService = this.getContainer().resolve(tokens_1.TOKENS.CalendarService); } async run() { // Initialize i18n service first await this.initI18nService(); // Language selection first await this.selectLanguage(); this.logStatus(this.t('init.messages.status')); const confirmed = await this.promptService.confirm(this.t('init.messages.confirm'), true); if (confirmed) { await this.verifyAuthentication(); } else { this.logResult(this.t('init.messages.cancelled')); } } async selectLanguage() { const languageOptions = [ { value: 'en', name: 'English' }, { value: 'ja', name: '日本語 (Japanese)' }, { value: 'es', name: 'Español (Spanish)' }, { value: 'de', name: 'Deutsch (German)' }, { value: 'pt', name: 'Português (Portuguese)' }, { value: 'fr', name: 'Français (French)' }, { value: 'ko', name: '한국어 (Korean)' }, ].filter((option) => languages_1.SUPPORTED_LANGUAGES.includes(option.value)); const selectedLanguage = await this.promptService.select('Select your preferred language:', languageOptions); await this.i18nService.changeLanguage(selectedLanguage); await this.configService.set('language', selectedLanguage); } async verifyAuthentication() { try { this.logStatus(this.t('init.messages.verifying')); // Test authentication by making a simple API call await this.calendarService.listCalendars(); this.logResult(this.t('init.messages.success')); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; this.logResult(this.t('init.messages.authenticationFailed', { error: errorMessage })); } } } exports.default = Init;