baidubce-cli
Advanced tools
Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "baidubce-cli", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "baidu cloud engine command line tools", | ||
@@ -31,4 +31,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "^1.4.2", | ||
"baidubce-sdk": "^0.0.16", | ||
"debug": "^2.1.3", | ||
"glob": "^5.0.14", | ||
"humanize": "0.0.9", | ||
@@ -35,0 +37,0 @@ "moment": "^2.8.4", |
@@ -50,2 +50,5 @@ /** | ||
.options('put-dir', {describe: 'Upload a directory', requiresArg: true}) | ||
.example('baidubce bos --put-dir my-dir bos://my-bucket/', 'Upload a directory') | ||
.options('copy-object', {describe: 'Copy object from one bucket to another', 'boolean': true}) | ||
@@ -116,4 +119,5 @@ .example('baidubce bos --copy-object bos://source/sk.js bos://target/tk.js <options>', | ||
'delete-buckets': deleteBuckets, | ||
'copy-object': copyObject | ||
'copy-object': copyObject, | ||
}; | ||
for (var ak in actionMap) { | ||
@@ -125,3 +129,3 @@ if (args[ak] === true) { | ||
if (args['put-object'] || args['put-superfile']) { | ||
if (args['put-dir'] || args['put-object'] || args['put-superfile']) { | ||
var destination = args._[0]; | ||
@@ -139,3 +143,6 @@ var match = kPattern.exec(destination); | ||
if (args['put-object']) { | ||
if (args['put-dir']) { | ||
return cmdPut.uploadDirectory(client, bucket_name, key, args['put-dir']); | ||
} | ||
else if (args['put-object']) { | ||
return cmdPut.putRegularFile(client, bucket_name, key, args['put-object']); | ||
@@ -334,6 +341,3 @@ } | ||
// 2. then check the -p or -s argument value the first step failed. | ||
var basename = path.basename(args['put-object'] || args['put-superfile']); | ||
if (!basename) { | ||
throw new Error('Invalid argument, can not find the object name'); | ||
} | ||
var basename = path.basename(args['put-object'] || args['put-superfile'] || ''); | ||
@@ -340,0 +344,0 @@ // 3. If the key end with slash, so it's directory, we need append the basename |
@@ -17,8 +17,55 @@ /** | ||
var u = require('underscore'); | ||
var glob = require('glob'); | ||
var async = require('async'); | ||
var Q = require('q'); | ||
var debug = require('debug')('cmd_put'); | ||
exports.uploadDirectory = function (client, bucket_name, key, directory) { | ||
debug('bucket_name = %j, key = %j, directory = %j', | ||
bucket_name, key, directory); | ||
var stat = fs.lstatSync(directory); | ||
if (!stat.isDirectory()) { | ||
throw new Error('Invalid file type'); | ||
} | ||
var failedItems = []; | ||
function iterator(item, callback) { | ||
var objectKey = key ? (key + item) : item; | ||
client.putObjectFromFile(bucket_name, objectKey, item) | ||
.then(function () { | ||
console.log('[DONE]:%s => bos://%s/%s', | ||
item, bucket_name, objectKey); | ||
}) | ||
.catch(function (error) { | ||
console.error(error); | ||
failedItems.push(item); | ||
}) | ||
.fin(callback); | ||
} | ||
function done() { | ||
if (failedItems.length) { | ||
console.log('\n -- FAILED ITEMS --'); | ||
console.log(failedItems.join('\n')); | ||
} | ||
else { | ||
console.log('All goes well.'); | ||
} | ||
} | ||
glob('**/*', {nodir: true, cwd: directory}, function (er, files) { | ||
async.eachLimit(files, 2, iterator, done); | ||
}); | ||
}; | ||
exports.putRegularFile = function (client, bucket_name, key, filename) { | ||
debug('putRegularFile bucket_name = %j, key = %j, filename = %j', | ||
bucket_name, key, filename); | ||
var stat = fs.lstatSync(filename); | ||
if (!stat.isFile()) { | ||
throw new Error('Invalid file type'); | ||
} | ||
client.putObjectFromFile(bucket_name, key, filename) | ||
@@ -34,2 +81,7 @@ .then(function () { | ||
exports.putSuperLargeFile = function (client, bucket_name, key, filename) { | ||
var stat = fs.lstatSync(filename); | ||
if (!stat.isFile()) { | ||
throw new Error('Invalid file type'); | ||
} | ||
var upload_id = null; | ||
@@ -36,0 +88,0 @@ client.initiateMultipartUpload(bucket_name, key) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49850
1180
10
+ Addedasync@^1.4.2
+ Addedglob@^5.0.14
+ Addedasync@1.5.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)