-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·106 lines (98 loc) · 2.35 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
#!/usr/bin/env node
const meow = require('meow')
const ftpup = require('./')
const cli = meow(`
Usage
$ ftpup [OPTION]... [SRC] [USERNAME[:PASSWORD]@]HOST[:DEST]
Options
-u, --username=USERNAME username
-p, --password=PASSWORD password
--secure explicit ftps over tls
--allow-unauthorized allow invalid certificates
--exclude=PATTERN exclude pattern
--purge=PATH purge directory
--scope=SCOPE scope name
--fresh ignore server state, perform fresh upload
--test perform a trial run with no changes made
-v, --version show version number
-h, --help show this help
Example
$ ftpup user@example.com
$ ftpup public user@example.com/subfolder
$ ftpup projectfolder --exclude node_modules user@example.com -p topsecret
`, {
flags: {
username: {
type: 'string',
alias: 'u',
},
password: {
type: 'string',
alias: 'p',
},
secure: {
type: 'boolean',
},
allowUnauthorized: {
type: 'boolean',
},
port: {
type: 'number',
},
exclude: {
type: 'string',
isMultiple: true,
},
purge: {
type: 'string',
isMultiple: true,
},
scope: {
type: 'string',
},
fresh: {
type: 'boolean',
},
test: {
type: 'boolean',
},
version: {
type: 'boolean',
alias: 'v',
},
},
})
const opts = {
port: cli.flags.port,
test: cli.flags.test,
fresh: cli.flags.fresh,
secure: cli.flags.secure,
allowUnauthorized: cli.flags.allowUnauthorized,
scope: cli.flags.scope,
purge: [ ...cli.flags.purge ],
}
if (cli.input.length == 2) {
Object.assign(opts, {
localDir: cli.input[0],
}, parseUri(cli.input[1]))
} else if (cli.input.length == 1) {
Object.assign(opts, parseUri(cli.input[0]))
} else {
cli.showHelp()
process.exit(0)
}
if (cli.flags.username) opts.username = cli.flags.username
if (cli.flags.password) opts.password = cli.flags.password
if (cli.flags.exclude) opts.exclude = [ ...cli.flags.exclude ]
ftpup(opts).catch(err => {
console.log('!', err.message)
})
function parseUri(uri) {
const m = uri.match(/((([^@:]+)(:([^@]+))?)@)?([\w\.]+)(\/(\S+))?/)
return {
host: m[6],
username: m[3],
password: m[5],
remoteDir: m[8],
}
}