UNPKG

soccer-go

Version:

Soccer CLI for stats and results.

107 lines (100 loc) 4.32 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __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 picocolors_1 = __importDefault(require("picocolors")); const commander_1 = __importDefault(require("commander")); const update_check_1 = require("./utils/update-check"); const errors_1 = require("./utils/errors"); 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 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 'Team': await commands.printTeam(answers.teamName, answers.teamOptions, league.code); break; } } catch (error) { (0, errors_1.handleCommandError)(error); } }; (async () => { commander_1.default.version(package_json_1.default.version); commander_1.default .command('standings <league>') .alias('s') .on('--help', () => console.log(` Get the full league table. Example: ${picocolors_1.default.green('sgo s SA')} Print Serie A table`)) .action((league) => commands.printStandings(league).catch(errors_1.handleCommandError)); commander_1.default .command('matchday <league>') .alias('m') .on('--help', () => console.log(` Get matchday for a given League. Example: ${picocolors_1.default.green('sgo m SA')} Print Serie A matchday`)) .action((league) => commands.printMatchday(league).catch(errors_1.handleCommandError)); commander_1.default .command('team <league> <team>') .alias('t') .option('-f, --fixtures', 'include fixtures') .option('-p, --players', 'include players') .on('--help', () => console.log(` Get team games and/or players. 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.fixtures ? 'Fixtures' : '', opts.players ? 'Players' : ''], league) .catch(errors_1.handleCommandError)); commander_1.default.command('*').action((cmd) => { (0, errors_1.handleCommandError)(new errors_1.ApplicationError(errors_1.ErrorCode.COMMAND_UNKNOWN, cmd)); }); if (process.argv.length === 2) { await askQuestions(); } commander_1.default.parse(process.argv); })(); process.on('uncaughtException', errors_1.handleCommandError); process.on('beforeExit', async () => { await (0, update_check_1.checkForUpdates)(package_json_1.default); });