bash completion support

This commit is contained in:
Trent Mick 2015-09-04 00:09:19 -07:00
parent f6f0843200
commit 411659180f
6 changed files with 66 additions and 5 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/node_modules /node_modules
/tmp /tmp
/build
/test/config.json /test/config.json
/npm-debug.log

10
.npmignore Normal file
View File

@ -0,0 +1,10 @@
/node_modules
/tmp
/test/config.json
/npm-debug.log
/deps
/examples
/tools
/Makefile
/TODO.txt
/test

View File

@ -70,6 +70,21 @@ Or non-interactively
joyent_20150826T120743Z joyent_20150826T120743Z
## Bash completion
You can quickly source `triton` bash completions in your current
shell with:
source <(triton completion)
For a more permanent installation:
triton completion >> ~/.bashrc
# Or maybe:
triton completion > /usr/local/etc/bash_completion.d/triton
## node-triton differences with node-smartdc ## node-triton differences with node-smartdc
- There is a single `sdc` command instead of a number of `sdc-FOO` commands. - There is a single `sdc` command instead of a number of `sdc-FOO` commands.

View File

@ -11,12 +11,11 @@ note in README that full UUIDs is much faster in the API
*type*: cloudapi changes to clarify: LX, docker, smartos, kvm instances *type*: cloudapi changes to clarify: LX, docker, smartos, kvm instances
bash completion: exclude '-J', better top/bottom comment boilerplate,
put the CLI's version in the top comment, ISO date format
# maybe next # maybe next
bash completion (subcmd options)
bash completion (cached data: insts, imgs, pkgs, names and ids)
PUBAPI-1117 triton create -c|--count N PUBAPI-1117 triton create -c|--count N
Rate limiting. Testing with non-op accounts. I suspect PUBAPI-1117 and other Rate limiting. Testing with non-op accounts. I suspect PUBAPI-1117 and other

View File

@ -229,9 +229,11 @@ CLI.prototype.init = function (opts, args, callback) {
// Meta
CLI.prototype.do_completion = require('./do_completion');
//CLI.prototype.do_profile = require('./do_profile'); //CLI.prototype.do_profile = require('./do_profile');
// Operator // Other
CLI.prototype.do_account = require('./do_account'); CLI.prototype.do_account = require('./do_account');
CLI.prototype.do_services = require('./do_services'); CLI.prototype.do_services = require('./do_services');
CLI.prototype.do_datacenters = require('./do_datacenters'); CLI.prototype.do_datacenters = require('./do_datacenters');

35
lib/do_completion.js Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015 Joyent Inc. All rights reserved.
*
* `triton completion ...`
*/
function do_completion(subcmd, opts, args, cb) {
if (opts.help) {
this.do_help('help', {}, [subcmd], cb);
return;
}
console.log(this.bashCompletion());
cb();
}
do_completion.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
}
];
do_completion.help = [
'Output bash completion code for the `triton` CLI.',
'',
'Installation:',
' triton completion >> ~/.bashrc',
'',
'Or maybe:',
' triton completion > /usr/local/etc/bash_completion.d/triton'
].join('\n');
do_completion.hidden = true;
module.exports = do_completion;