11/** @format */
22
3- const { Component } = require ( '@serverless-devs/s- core' ) ;
3+ const { commandParse , help , getCredential } = require ( '@serverless-devs/core' ) ;
44const ClientProvider = require ( './utils/client-provider' ) ;
55const { REGIONLIST } = require ( './utils/constants' ) ;
66
7- class MyComponent extends Component {
8- handlerInput ( inputs ) {
9- const {
10- Credentials,
11- Properties
7+ class MyComponent {
8+ async handlerInput ( inputs ) {
9+ let {
10+ credentials,
11+ props,
12+ project = { } ,
1213 } = inputs ;
14+ if ( ! ( credentials && credentials . AccessKeyID ) ) {
15+ credentials = await getCredential ( project . access ) ;
16+ }
1317
1418 return {
15- accessKeyId : Credentials . AccessKeyID ,
16- accessKeySecret : Credentials . AccessKeySecret ,
17- securityToken : Credentials . SecurityToken ,
18- accountID : Credentials . AccountID ,
19+ accessKeyId : credentials . AccessKeyID ,
20+ accessKeySecret : credentials . AccessKeySecret ,
21+ securityToken : credentials . SecurityToken ,
22+ accountID : credentials . AccountID ,
1923
20- region : Properties . Region ,
21- bucketName : Properties . BucketName ,
22- objectPath : Properties . ObjectPath || '' ,
23- ignore : Properties . Ignore || [ ] ,
24- uri : Properties . Uri
24+ region : props . Region ,
25+ bucketName : props . BucketName ,
26+ objectPath : props . ObjectPath || '' ,
27+ ignore : props . Ignore || [ ] ,
28+ uri : props . Uri
2529 }
2630 }
2731
@@ -35,8 +39,26 @@ class MyComponent extends Component {
3539 }
3640
3741 async upload ( inputs ) {
38- const { Parameters } = this . args ( inputs . Args ) ;
39- const { y, n } = Parameters ;
42+ const { Parameters = { } } = commandParse ( inputs . args ) || { } ;
43+ const { y, n, h } = Parameters ;
44+ if ( h ) {
45+ return help ( {
46+ header : 'Options' ,
47+ optionList : [
48+ {
49+ name : 'y' ,
50+ description : '覆盖 ObjectPath 已经存在的文件' ,
51+ type : Boolean ,
52+ } ,
53+ {
54+ name : 'n' ,
55+ description : '不上传 ObjectPath 已经存在的文件' ,
56+ type : Boolean ,
57+ } ,
58+ ] ,
59+ } ) ;
60+ }
61+
4062 if ( y && n ) {
4163 throw new Error ( '-y 和 -n 不能同时存在' ) ;
4264 }
@@ -51,7 +73,7 @@ class MyComponent extends Component {
5173 objectPath,
5274 ignore,
5375 uri
54- } = this . handlerInput ( inputs ) ;
76+ } = await this . handlerInput ( inputs ) ;
5577
5678 if ( ! region ) {
5779 throw new Error ( 'Region 是必填项' ) ;
0 commit comments