-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
152 lines (144 loc) · 5.64 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const main = require('./index')
const _ = require('lodash')
const moment = require('moment')
const cli = meow(`
Usage
$ node cli.js <input> [opts]
Arguments
quad Show quad birds
first Show your entire first time lists
big Show all your biggest time periods
big-year Show your biggest year
big-month Show your biggest month
big-day Show your biggest day
first-year Show your first lists
first-month Show your first lists
first-day Show your first lists
towns Show your town counts
regions Show your region counts
Options
--input, -i The input file
--country Search by country
--state Search by state
--county Search by county
--year Limit results to a given year
--town Search by towns in Vemront
--region Search by biophysical regions in Vermont
--list, -l List all of the species
Examples
$ node cli.js
`, {
flags: {
input: {
type: 'string',
alias: 'i'
},
country: {
type: 'string'
},
county: {
type: 'string'
},
state: {
type: 'string'
},
year: {
type: 'string'
},
town: {
type: 'string'
},
list: {
type: 'boolean',
alias: 'l'
},
towns: {
type: 'string'
},
regions: {
type: 'string'
}
}
})
// TODO Make Country, State, and County mutually exclusive
// TODO Make input automatic based on file location
// TODO This is ugly. Make it better.
async function run () {
if (cli.input[0] === 'quad') {
await main.quadBirds(cli.flags)
} else if (cli.input[0] === 'towns') {
await main.towns(cli.flags)
} else if (cli.input[0] === 'regions') {
await main.regions(cli.flags)
} else if (cli.input[0] === 'big') {
cli.flags.list = undefined
let timespan = 'year'
let biggest = await main.biggestTime(timespan, cli.flags)
console.log(`Your biggest ${timespan} was ${biggest.Date} with ${biggest.SpeciesTotal} new species.`)
timespan = 'month'
biggest = await main.biggestTime(timespan, cli.flags)
console.log(`Your biggest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM YYYY')} with ${biggest.SpeciesTotal} new species.`)
timespan = 'day'
biggest = await main.biggestTime(timespan, cli.flags)
console.log(`Your biggest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM Do, YYYY')} with ${biggest.SpeciesTotal} new species.`)
} else if (cli.input[0] === 'first') {
cli.flags.list = undefined
let timespan = 'year'
let biggest = await main.firstTimes(timespan, cli.flags)
console.log(`Your newest ${timespan} was ${biggest.Date} with ${biggest.SpeciesTotal} new species.`)
timespan = 'month'
biggest = await main.firstTimes(timespan, cli.flags)
console.log(`Your newest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM YYYY')} with ${biggest.SpeciesTotal} new species.`)
timespan = 'day'
biggest = await main.firstTimes(timespan, cli.flags)
console.log(`Your newest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM Do, YYYY')} with ${biggest.SpeciesTotal} new species.`)
} else if (cli.input[0] === 'big-year') {
const timespan = 'year'
const biggest = await main.biggestTime(timespan, cli.flags)
console.log(`Your biggest ${timespan} was ${biggest.Date} with ${biggest.SpeciesTotal} species.`)
if (cli.flags.list) {
console.log(`With these species: ${_.map(biggest.Species, 'Scientific Name').join(', ')}.`)
}
} else if (cli.input[0] === 'big-month') {
const timespan = 'month'
const biggest = await main.biggestTime(timespan, cli.flags)
console.log(`Your biggest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM YYYY')} with ${biggest.SpeciesTotal} species.`)
if (cli.flags.list) {
console.log(`With these species: ${_.map(biggest.Species, 'Scientific Name').join(', ')}.`)
}
} else if (cli.input[0] === 'big-day') {
const timespan = 'day'
const biggest = await main.biggestTime(timespan, cli.flags)
console.log(`Your biggest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM Do, YYYY')} with ${biggest.SpeciesTotal} species.`)
if (cli.flags.list) {
console.log(`With these species: ${_.map(biggest.Species, 'Scientific Name').join(', ')}.`)
}
} else if (cli.input[0] === 'first-year') {
const timespan = 'year'
const biggest = await main.firstTimes(timespan, cli.flags)
console.log(`Your newest ${timespan} was ${biggest.Date} with ${biggest.SpeciesTotal} new species.`)
if (cli.flags.list) {
console.log(`With these species: ${_.map(biggest.Species, 'Scientific Name').join(', ')}.`)
}
} else if (cli.input[0] === 'first-month') {
const timespan = 'month'
const biggest = await main.firstTimes(timespan, cli.flags)
console.log(`Your newest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM YYYY')} with ${biggest.SpeciesTotal} new species.`)
if (cli.flags.list) {
console.log(`With these species: ${_.map(biggest.Species, 'Scientific Name').join(', ')}.`)
}
} else if (cli.input[0] === 'first-day') {
const timespan = 'day'
const biggest = await main.firstTimes(timespan, cli.flags)
console.log(`Your newest ${timespan} was ${moment(biggest.Date, 'YYYY-MM-DD').format('MMMM Do, YYYY')} with ${biggest.SpeciesTotal} new species.`)
if (cli.flags.list) {
console.log(`With these species: ${_.map(biggest.Species, 'Scientific Name').join(', ')}.`)
}
} else {
console.log(cli.showHelp())
}
}
run()