UNPKG

soccer-go

Version:

Soccer CLI for stats and results.

153 lines (149 loc) 6.38 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const extra_typings_1 = require("@commander-js/extra-typings"); const picocolors_1 = __importDefault(require("picocolors")); const package_json_1 = __importDefault(require("../package.json")); const commands = __importStar(require("./commands")); const leagues_1 = require("./constants/leagues"); const questions_1 = require("./constants/questions"); const errors_1 = require("./utils/errors"); const update_check_1 = require("./utils/update-check"); const askQuestions = async () => { try { const answers = await (0, questions_1.questions)(); const league = (0, leagues_1.getLeagueByName)(answers.league); switch (answers.main) { case 'matchday': await commands.printMatchday(league.code); break; case 'standings': await commands.printStandings(league.code); break; case 'scorers': await commands.printScorers(league.code); break; case 'team': await commands.printTeam(answers.teamName, answers.teamOptions, league.code); break; } } catch (error) { // Handle cancellation gracefully if (error instanceof Error && error.name === 'ExitPromptError') { process.exit(0); } (0, errors_1.handleCommandError)(error); } }; (async () => { if (process.argv.length === 2) { await askQuestions(); return; } const program = new extra_typings_1.Command(); program .name('sgo') .description('⚽ Get soccer stats and results from your terminal') .version(package_json_1.default.version) .addHelpText('after', ` Examples: ${picocolors_1.default.green('sgo')} Run in interactive mode ${picocolors_1.default.green('sgo standings PL')} Show Premier League table ${picocolors_1.default.green('sgo scorers PL')} Show Premier League top scorers ${picocolors_1.default.green('sgo matchday SA')} Show Serie A matchday fixtures ${picocolors_1.default.green('sgo team PL arsenal -f')} Show Arsenal fixtures League Codes: PL (Premier League), SA (Serie A), BL1 (Bundesliga), PD (La Liga), FL1 (Ligue 1), CL (Champions League), etc. Run ${picocolors_1.default.cyan('sgo')} with no arguments for interactive mode. `); program .command('standings') .alias('s') .argument('<league>', 'League code (e.g., PL, SA, BL1)') .description('Get the full league table') .addHelpText('after', ` Example: ${picocolors_1.default.green('sgo s SA')} Print Serie A table `) .action((league) => commands.printStandings(league).catch(errors_1.handleCommandError)); program .command('matchday') .alias('m') .argument('<league>', 'League code (e.g., PL, SA, BL1)') .description('Get matchday fixtures for a given league') .option('-d, --details', 'Include additional details (e.g., referee)') .addHelpText('after', ` Example: ${picocolors_1.default.green('sgo m SA')} Print Serie A matchday ${picocolors_1.default.green('sgo m PL --details')} Print with additional details (referee) `) .action((league, opts) => commands.printMatchday(league, opts.details).catch(errors_1.handleCommandError)); program .command('scorers') .alias('sc') .argument('<league>', 'League code (e.g., PL, SA, BL1)') .description('Get top scorers for a given league') .addHelpText('after', ` Example: ${picocolors_1.default.green('sgo sc PL')} Print Premier League top scorers `) .action((league) => commands.printScorers(league).catch(errors_1.handleCommandError)); program .command('team') .alias('t') .argument('<league>', 'League code (e.g., PL, SA, BL1)') .argument('<team>', 'Team name (use quotes for multi-word names)') .description('Get team information, fixtures, and players') .option('-f, --fixtures', 'Include fixtures') .option('-p, --players', 'Include player infos') .option('-d, --details', 'Include additional details (e.g., referee)') .addHelpText('after', ` Example: ${picocolors_1.default.green('sgo t SA roma -f')} Print AS Roma fixtures ${picocolors_1.default.green('sgo t PD "real madrid" -p')} Print Real Madrid players `) .action((league, team, opts) => commands.printTeam(team, opts, league).catch(errors_1.handleCommandError)); program.parse(process.argv); })(); process.on('uncaughtException', errors_1.handleCommandError); process.on('beforeExit', async () => { await (0, update_check_1.checkForUpdates)(package_json_1.default); });