From 411659180fa2e800631cbcf068544aa2dff8f2db Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 4 Sep 2015 00:09:19 -0700 Subject: [PATCH] bash completion support --- .gitignore | 2 +- .npmignore | 10 ++++++++++ README.md | 15 +++++++++++++++ TODO.txt | 5 ++--- lib/cli.js | 4 +++- lib/do_completion.js | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 .npmignore create mode 100644 lib/do_completion.js diff --git a/.gitignore b/.gitignore index f8990d2..c2f0dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /node_modules /tmp -/build /test/config.json +/npm-debug.log diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..a941a01 --- /dev/null +++ b/.npmignore @@ -0,0 +1,10 @@ +/node_modules +/tmp +/test/config.json +/npm-debug.log +/deps +/examples +/tools +/Makefile +/TODO.txt +/test diff --git a/README.md b/README.md index b261101..dfae536 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,21 @@ Or non-interactively 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 - There is a single `sdc` command instead of a number of `sdc-FOO` commands. diff --git a/TODO.txt b/TODO.txt index 888a14b..cf825f6 100644 --- a/TODO.txt +++ b/TODO.txt @@ -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 +bash completion: exclude '-J', better top/bottom comment boilerplate, +put the CLI's version in the top comment, ISO date format # maybe next -bash completion (subcmd options) -bash completion (cached data: insts, imgs, pkgs, names and ids) - PUBAPI-1117 triton create -c|--count N Rate limiting. Testing with non-op accounts. I suspect PUBAPI-1117 and other diff --git a/lib/cli.js b/lib/cli.js index 09576f5..eec932b 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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'); -// Operator +// Other CLI.prototype.do_account = require('./do_account'); CLI.prototype.do_services = require('./do_services'); CLI.prototype.do_datacenters = require('./do_datacenters'); diff --git a/lib/do_completion.js b/lib/do_completion.js new file mode 100644 index 0000000..c2331d5 --- /dev/null +++ b/lib/do_completion.js @@ -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;