canigethigh
Version:
Legality of cannabis by country
85 lines (67 loc) • 2.11 kB
JavaScript
const meow = require('meow')
const updateNotifier = require('update-notifier')
const got = require('got')
const chalk = require('chalk')
const ora = require('ora')
const spinner = ora()
const cli = meow(`
Usage
$ canigethigh
$ canigethigh <country>
Example
$ canigethigh brazil
$ canigethigh united-states
Help
$ canigethigh --help
`)
const apiUrl = 'https://canigethigh-api-ptltgihqjh.now.sh/countries'
const prop = cli.input[0]
updateNotifier({pkg: cli.pkg}).notify()
if (cli.flags.help || cli.flags.h) {
cli.showHelp()
} else if (cli.input.length > 0) {
spinner.start()
got(`${apiUrl}/${prop}`)
.then(response => {
spinner.stop()
let country = JSON.parse(response.body)
let output = [
`
${chalk.bold.yellow('⇢ Country:')} ${chalk.bold(country[0].name)}
${chalk.bold.yellow('⇢ Continent:')} ${chalk.bold(country[0].continent)}
${chalk.bold.yellow('⇢ Possession:')} ${chalk.bold(country[0].possession)}
${chalk.bold.yellow('⇢ Sale:')} ${chalk.bold(country[0].sale)}
${chalk.bold.yellow('⇢ Transport:')} ${chalk.bold(country[0].transport)}
${chalk.bold.yellow('⇢ Cultivation:')} ${chalk.bold(country[0].cultivation)}`
]
console.log(output.join('\n'))
process.exit(0)
})
.catch(err => {
console.log(err)
})
} else {
spinner.start()
got(apiUrl)
.then(response => {
spinner.stop()
let country = JSON.parse(response.body).map((res) => {
let output = [
`
${chalk.bold.yellow('⇢ Country:')} ${chalk.bold(res.name)}
${chalk.bold.yellow('⇢ Continent:')} ${chalk.bold(res.continent)}
${chalk.bold.yellow('⇢ Possession:')} ${chalk.bold(res.possession)}
${chalk.bold.yellow('⇢ Sale:')} ${chalk.bold(res.sale)}
${chalk.bold.yellow('⇢ Transport:')} ${chalk.bold(res.transport)}
${chalk.bold.yellow('⇢ Cultivation:')} ${chalk.bold(res.cultivation)}`
]
console.log(output.join('\n'))
})
process.exit(0)
})
.catch(err => {
console.log(err)
})
}