forked from wangsijie/static-deploy-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·104 lines (96 loc) · 2.63 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
#!/usr/bin/env node
const program = require('commander');
const sync = require('./sync');
const put = require('./put');
const copy = require('./copy');
const get = require('./get');
program
.version('1.2.0')
.option('-k, --ak [ak]', 'Access Key Id')
.option('-s, --sk [sk]', 'Secret Access Key')
.option('-r, --region [region]', 'Region')
.option('-b, --bucket [bucket]', 'Bucket')
.option('-e, --endpoint [endpoint]', 'Optional, will override region setting')
.option('-f, --force [force]', 'Optional, force get object and override')
program
.command('sync <local> <remote>')
.action(async (local, remote) => {
try {
await sync({
local,
remote,
aliyun: checkParams(),
})
} catch (e) {
console.error(e);
process.exit(1);
}
})
program
.command('put <local> <remote>')
.action(async (local, remote) => {
try {
await put({
local,
remote,
aliyun: checkParams(),
})
} catch (e) {
console.error(e.message);
process.exit(1);
}
})
program
.command('copy <source> <dest>')
.action(async (source, dest) => {
try {
await copy({
source,
dest,
aliyun: checkParams(),
})
} catch (e) {
console.error(e.message);
process.exit(1);
}
})
program
.command('get <remote> <local>')
.action(async (remote, local) => {
try {
await get({
local,
remote,
aliyun: checkParams(),
force: program.force
})
} catch (e) {
console.error(e.message);
process.exit(1);
}
})
program.parse(process.argv);
function checkParams() {
const ak = program.ak || process.env.OSS_AK;
const sk = program.sk || process.env.OSS_SK;
const region = program.region || process.env.OSS_REGION;
const bucket = program.bucket || process.env.OSS_BUCKET;
const endpoint = program.endpoint || process.env.OSS_ENDPOINT;
if (!ak) {
console.error('AK is missing');
process.exit(1)
}
if (!sk) {
console.error('SK is missing');
process.exit(1)
}
if (!bucket) {
console.error('Bucket is missing');
process.exit(1)
}
if (!region && !endpoint) {
console.error('Region or endpoint is missing');
process.exit(1);
}
return { ak, sk, region, bucket, endpoint };
}