UNPKG

gcal-commander

Version:

A command-line interface for Google Calendar operations

102 lines (101 loc) 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCommand = void 0; const core_1 = require("@oclif/core"); const tsyringe_1 = require("tsyringe"); const tokens_1 = require("./di/tokens"); const fields_parser_1 = require("./utils/fields-parser"); class BaseCommand extends core_1.Command { static baseFlags = { fields: core_1.Flags.string({ description: 'Comma-separated list of fields to display in table format', helpValue: 'field1,field2,...', }), format: core_1.Flags.string({ char: 'f', default: 'table', description: 'Output format', options: ['json', 'pretty-json', 'table'], }), quiet: core_1.Flags.boolean({ char: 'q', default: false, description: 'Suppress non-essential output (status messages, progress indicators)', }), }; authService; calendarService; configService; fields; format = 'table'; i18nService; quiet = false; getContainer() { return tsyringe_1.container; } async init() { await super.init(); const { flags } = await this.parse(this.constructor); this.fields = (0, fields_parser_1.parseFields)(flags.fields); this.format = flags.format; this.quiet = flags.quiet; // Initialize services using TSyringe container this.authService = this.getContainer().resolve(tokens_1.TOKENS.AuthService); this.configService = this.getContainer().resolve(tokens_1.TOKENS.ConfigService); } /** * Initialize calendar service with authentication * Must be called by commands that need calendar access */ async initCalendarService() { this.calendarService = this.getContainer().resolve(tokens_1.TOKENS.CalendarService); } /** * Initialize i18n service for translations * Must be called by commands that need i18n support */ async initI18nService() { if (!this.i18nService) { this.i18nService = this.getContainer().resolve(tokens_1.TOKENS.I18nService); // Try to load saved language setting from config, fallback to undefined (English default) let savedLanguage; try { savedLanguage = await this.configService.get('language'); } catch { // If config loading fails, use default language (English) savedLanguage = undefined; } await this.i18nService.init(savedLanguage); } } logError(message) { this.error(message); } logResult(message) { this.log(message); } logStatus(message) { if (!this.quiet) { this.logToStderr(message); } } outputJson(data) { if (this.format === 'pretty-json') { this.logResult(JSON.stringify(data, null, 2)); } else if (this.format === 'json') { this.logResult(JSON.stringify(data)); } else { this.logJson(data); } } t(key, options) { if (!this.i18nService) { throw new Error('I18n service not initialized. Call initI18nService() first.'); } return this.i18nService.t(key, options); } } exports.BaseCommand = BaseCommand;