Skip to content

Commit

Permalink
Merge pull request #8 from a0viedo/add-url-option
Browse files Browse the repository at this point in the history
feat(cli): add url option
  • Loading branch information
durancristhian authored Jul 12, 2016
2 parents a56e00b + 9c1c6da commit f3a5517
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ 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
const url = require('url')

commander
.usage('--meetup-name [MEETUP_NAME] --event-id [EVENT_ID]')
.usage('--url [EVENT_URL] --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
.option('-u, --url <EVENT_URL>', `event's url. For example:`) // eslint-disable-line quotes
.parse(process.argv)

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

if (commander.url) {
const path = url.parse(commander.url).path
const pathSlices = path.split('/')
commander.eventId = pathSlices[pathSlices.length - 2]
commander.meetupName = pathSlices[pathSlices.length - 4]
}

program(API_URL, PROFILE_URL, commander.meetupName, commander.eventId)
.then(winner => {
showWinnerImage(winner)
Expand Down

0 comments on commit f3a5517

Please sign in to comment.