UNPKG

oss-upload-tool

Version:
1 lines 2.33 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=parseArgv;var _stanUtils=require("stan-utils"),_consts=require("../consts"),_utils=require("../utils"),pkg=require("../../package.json");function parseArgv(t){var e;_stanUtils.commander.parse(t);var s=_stanUtils.commander.opts(),n=[];if(null!=s&&null!==(e=s.targets)&&void 0!==e&&e.length||n.push("Please specify the file to upload, use -t."),n.length)return console.error(_stanUtils.chalk.red("".concat(pkg.name," error:"))),void n.forEach((function(t){console.error(_stanUtils.chalk.redBright(" "+t))}));var o=s.secret_id,r=s.secret_key,i=s.bucket,a=s.region,l=s.endpoint,c=s.existCheck;return(0,_utils.safeSetEnv)(_consts.SECRET_ID,o),(0,_utils.safeSetEnv)(_consts.SECRET_KEY,r),(0,_utils.safeSetEnv)(_consts.BUCKET_KEY,i),(0,_utils.safeSetEnv)(_consts.REGION_KEY,a),(0,_utils.safeSetEnv)(_consts.ALIOSS_ENDPOINT_KEY,l),{cwd:process.cwd(),verbose:!!s.verbose,type:s.oss,targets:((null==s?void 0:s.targets)||[]).filter(Boolean).map((function(t){return{src:t,dest:s.dest,flatten:s.flatten}})),existCheck:c}}function collect(t,e){if("string"!=typeof t)return e;var s=t.split(",");return e?e.concat(s):s}function booleanify(t){return"true"===t||1==t||!("false"===t||0==t||!t)&&t}_stanUtils.commander.option("-V, --verbose","Output verbose messages on internal operations"),_stanUtils.commander.option("--oss [COS|ALI|S3]","OSS Type only supported COS|ALI|S3"),_stanUtils.commander.option("-t, --targets <list>","Upload targets local path",collect),_stanUtils.commander.option("-d, --dest <list>","Upload remote directory",collect),_stanUtils.commander.option("--flatten","Delete the directory structure of uploaded files",booleanify),_stanUtils.commander.option("--secret_id [string]","OSS SecretId params"),_stanUtils.commander.option("--secret_key [string]","OSS SecretKey params"),_stanUtils.commander.option("--bucket [string]","OSS Bucket params"),_stanUtils.commander.option("--origin [string]","Accessible cdn address"),_stanUtils.commander.option("--existCheck [string]","If the file exists, skip uploading"),_stanUtils.commander.option("--region [string]","OSS Region params"),_stanUtils.commander.option("--endpoint [string]","Ali OSS endpoint params"),_stanUtils.commander.name(pkg.name),_stanUtils.commander.version(pkg.version);