This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
node-spearhead/lib/do_keys.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-08-26 07:40:32 +03:00
/*
2015-09-04 21:12:20 +03:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Copyright 2015 Joyent, Inc.
2015-08-26 07:40:32 +03:00
*
* `triton keys ...`
2015-08-26 07:40:32 +03:00
*/
var common = require('./common');
function do_keys(subcmd, opts, args, callback) {
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 0) {
callback(new Error('invalid args: ' + args));
return;
}
this.tritonapi.cloudapi.listKeys(function (err, keys) {
2015-08-26 07:40:32 +03:00
if (err) {
callback(err);
return;
}
if (opts.json) {
2015-08-26 23:53:23 +03:00
common.jsonStream(keys);
2015-08-26 07:40:32 +03:00
} else {
// pretty print
keys.forEach(function (key) {
console.log(key.key);
});
}
callback();
});
}
do_keys.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
{
names: ['json', 'j'],
type: 'bool',
help: 'JSON output.'
}
];
do_keys.help = (
2015-10-19 19:03:39 +03:00
'Show account keys.\n'
2015-08-26 07:40:32 +03:00
+ '\n'
+ 'Usage:\n'
+ ' {{name}} keys\n'
+ '\n'
+ '{{options}}'
);
module.exports = do_keys;