Created
August 9, 2018 04:46
-
-
Save Tolsee/294b139d6e4bd97b5c55593218c68d7c to your computer and use it in GitHub Desktop.
Adding spinner to list command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gEvent | |
.command('list') | |
.option('-f, --from [date]', 'Get events from the date[chrono based date parsing]') | |
.option('-t, --to [date]', 'Get events until the date[chrono based date parsing]') | |
.option('-r, --results <events>', 'Number of events to show') | |
.description('List google event') | |
.action(async function(args, callback) { | |
const spinner = new Spinner('Syncing data.. %s'); | |
spinner.setSpinnerString('▖▘▝▗'); | |
spinner.start(); | |
const calendar = google.calendar({ | |
version: 'v3', | |
auth: oauth2Client | |
}); | |
let options = { | |
calendarId: 'primary', | |
singleEvents: true, | |
maxResults: 10 | |
}; | |
if(args.options.from) { | |
const time = chrono.parseDate(args.options.from); | |
if (time) { | |
options.timeMin = time.toISOString(); | |
} else { | |
this.log(Yellow('Warning: cannot parse from date')); | |
} | |
} | |
if(args.options.to) { | |
const time = chrono.parseDate(args.options.to); | |
if (time) { | |
options.timeMax = time.toISOString(); | |
} else { | |
this.log(Yellow('Warning: cannot parse to date')); | |
} | |
} | |
if(args.options.results) options.maxResults = args.options.results; | |
const res = await calendar.events.list(options); | |
spinner.stop(); | |
const data = res.data; | |
this.log(Email('Email: '), data.summary); | |
this.log(); | |
data.items.forEach(({ summary, start, end, location, htmlLink }) => { | |
this.log(Summary(summary)); | |
this.log(); | |
const startTime = moment(start.dateTime).format('MMMM Do YYYY, h:mm:ss a'); | |
const endTime = moment(end.dateTime).format('MMMM Do YYYY, h:mm:ss a'); | |
this.log(Time('Start Time: '), startTime, ' ', Time('Start Time: '), endTime); | |
this.log(Location(location || 'Location is not available.')); | |
this.log(htmlLink); | |
this.log(); | |
this.log(); | |
}); | |
callback(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment