#! /usr/bin/env node

const commander = require('commander')
const program = require('../lib/program')
const showWinnerImage = require('../lib/modules/show-winner-image')
const API_URL = process.env.API_URL
const PROFILE_URL = process.env.PROFILE_URL

commander
  .usage('--meetup-name [MEETUP_NAME] --event-id [EVENT_ID]')
  .option('-m, --meetup-name <MEETUP_NAME>', `meetup's name. For example: banodejs`) // eslint-disable-line quotes
  .option('-e, --event-id <EVENT_ID>', `event's id. For example: 231888421`) // eslint-disable-line quotes
  .parse(process.argv)

if (!commander.meetupName || !commander.eventId) {
  commander.help()
}

program(API_URL, PROFILE_URL, commander.meetupName, commander.eventId)
  .then(winner => {
    showWinnerImage(winner)
      .catch(error => {
        console.log(`There was an error when we tried to show the winner's image`) // eslint-disable-line quotes
        console.log(`Error description: ${error.message}`) // eslint-disable-line quotes
      })
      .then(winner => console.log(JSON.stringify(winner, null, 2)))
  })
  .catch(error => {
    console.error(error)

    process.exit(1)
  })

@@ -243,16 +243,43 @@
 FILE_URL
+%0Aconst url = require('url')
 %0A%0Acomman
@@ -292,16 +292,34 @@
 .usage('
+--url %5BEVENT_URL%5D 
 --meetup
@@ -584,16 +584,110 @@
  quotes%0A
+  .option('-u, --url %3CEVENT_URL%3E', %60event's url. For example:%60) // eslint-disable-line quotes%0A
   .parse
@@ -704,16 +704,35 @@
 rgv)%0A%0Aif
+ (!commander.url &&
  (!comma
@@ -769,16 +769,17 @@
 eventId)
+)
  %7B%0A  com
@@ -795,16 +795,237 @@
 lp()%0A%7D%0A%0A
+if (commander.url) %7B%0A  const path = url.parse(commander.url).path%0A  const pathSlices = path.split('/')%0A  commander.eventId = pathSlices%5BpathSlices.length - 2%5D%0A  commander.meetupName = pathSlices%5BpathSlices.length - 4%5D%0A%7D%0A%0A
 program(

add url option