-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
64 lines (54 loc) · 1.55 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
#!/usr/bin/env node
var verifyDate = require('./src/verify-date')
var gdrive = require('./src/commands')
var yargs = require('yargs')
.usage('$0 <command>')
.command('ls', 'List all files within a given folder', listFilesCommand)
.command('get-all', 'Download all files within a given folder', downloadFilesCommand)
.help('help')
.required(1, '')
yargs.argv
function listFilesCommand(yargs) {
var args = yargs
.usage('$0 ls <path>')
.required(2, 'The path is required. It is case-sensitive. Use `/` for the root.')
.option('modified-after', {
alias: 'm',
describe: 'json date, it will only return matches modified after this date',
})
.help('help')
.argv
var path = args._[1]
var opts = {
modifiedAfter: verifyDate(args.modifiedAfter),
}
hookUpOutput(gdrive.listFiles(path, opts))
}
function downloadFilesCommand(yargs) {
var args = yargs
.usage('$0 get-all <path>')
.required(2, 'The path is required. It is case-sensitive. Use `/` for the root.')
.option('modified-after', {
alias: 'm',
describe: 'json date, it will only return matches modified after this date',
})
.option('output-dir', {
alias: 'o',
describe: 'The folder to download to. The default is the current folder',
})
.help('help')
.argv
var path = args._[1]
var opts = {
modifiedAfter: verifyDate(args.modifiedAfter),
outputDir: args.outputDir,
}
hookUpOutput(gdrive.getFiles(path, opts))
}
function hookUpOutput(promise) {
promise.then(function(result) {
console.log(JSON.stringify(result, null, ' '))
}, function(e) {
console.error(e)
})
}