bash completion for 'triton account update <TAB>'
This commit is contained in:
		
							parent
							
								
									5ee94b04af
								
							
						
					
					
						commit
						989a43f367
					
				@ -2,6 +2,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## 4.2.0 (not yet released)
 | 
					## 4.2.0 (not yet released)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Bash completion: Add completion for *args* to `triton account update <TAB>`.
 | 
				
			||||||
 | 
					  This isn't perfect because a space is added after completion of "FIELD=",
 | 
				
			||||||
 | 
					  but hopefully is helpful.
 | 
				
			||||||
- #75 `triton account update ...`
 | 
					- #75 `triton account update ...`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -6,3 +6,10 @@ function complete_tritonprofile {
 | 
				
			|||||||
        | sed -E 's/^.*\/([^\/]+)\.json$/\1/')
 | 
					        | sed -E 's/^.*\/([^\/]+)\.json$/\1/')
 | 
				
			||||||
    compgen $compgen_opts -W "$candidates" -- "$word"
 | 
					    compgen $compgen_opts -W "$candidates" -- "$word"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function complete_tritonupdateaccountfield {
 | 
				
			||||||
 | 
					    local word="$1"
 | 
				
			||||||
 | 
					    local candidates
 | 
				
			||||||
 | 
					    candidates="{{UPDATE_ACCOUNT_FIELDS}}"
 | 
				
			||||||
 | 
					    compgen $compgen_opts -W "$candidates" -- "$word"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -915,7 +915,8 @@ function objFromKeyValueArgs(args, opts)
 | 
				
			|||||||
    args.forEach(function (arg) {
 | 
					    args.forEach(function (arg) {
 | 
				
			||||||
        var kv = strsplit(arg, '=', 2);
 | 
					        var kv = strsplit(arg, '=', 2);
 | 
				
			||||||
        if (kv.length < 2) {
 | 
					        if (kv.length < 2) {
 | 
				
			||||||
            throw new TypeError(format('invalid key=value argument: "%s"'));
 | 
					            throw new TypeError(format('invalid key=value argument: "%s"',
 | 
				
			||||||
 | 
					                arg));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var k = kv[0];
 | 
					        var k = kv[0];
 | 
				
			||||||
 | 
				
			|||||||
@ -169,4 +169,6 @@ do_update.help = [
 | 
				
			|||||||
    /* END JSSTYLED */
 | 
					    /* END JSSTYLED */
 | 
				
			||||||
].join('\n');
 | 
					].join('\n');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					do_update.completionArgtypes = ['tritonupdateaccountfield'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = do_update;
 | 
					module.exports = do_update;
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,17 @@
 | 
				
			|||||||
var fs = require('fs');
 | 
					var fs = require('fs');
 | 
				
			||||||
var path = require('path');
 | 
					var path = require('path');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var UPDATE_ACCOUNT_FIELDS
 | 
				
			||||||
 | 
					    = require('./cloudapi2').CloudApi.prototype.UPDATE_ACCOUNT_FIELDS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Replace {{variable}} in `s` with the template data in `d`.
 | 
				
			||||||
 | 
					function renderTemplate(s, d) {
 | 
				
			||||||
 | 
					    return s.replace(/{{([a-zA-Z_]+)}}/g, function (match, key) {
 | 
				
			||||||
 | 
					        return d.hasOwnProperty(key) ? d[key] : match;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function do_completion(subcmd, opts, args, cb) {
 | 
					function do_completion(subcmd, opts, args, cb) {
 | 
				
			||||||
    if (opts.help) {
 | 
					    if (opts.help) {
 | 
				
			||||||
@ -23,9 +34,13 @@ function do_completion(subcmd, opts, args, cb) {
 | 
				
			|||||||
    if (opts.raw) {
 | 
					    if (opts.raw) {
 | 
				
			||||||
        console.log(this.bashCompletionSpec());
 | 
					        console.log(this.bashCompletionSpec());
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        var specExtra = fs.readFileSync(
 | 
					        var specExtraIn = fs.readFileSync(
 | 
				
			||||||
            path.join(__dirname, '../etc/triton-bash-completion-types.sh'),
 | 
					            path.join(__dirname, '../etc/triton-bash-completion-types.sh'),
 | 
				
			||||||
            'utf8');
 | 
					            'utf8');
 | 
				
			||||||
 | 
					        var specExtra = renderTemplate(specExtraIn, {
 | 
				
			||||||
 | 
					            UPDATE_ACCOUNT_FIELDS: Object.keys(UPDATE_ACCOUNT_FIELDS).sort()
 | 
				
			||||||
 | 
					                .map(function (field) { return field + '='; }).join(' ')
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
        console.log(this.bashCompletion({specExtra: specExtra}));
 | 
					        console.log(this.bashCompletion({specExtra: specExtra}));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    cb();
 | 
					    cb();
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,7 @@
 | 
				
			|||||||
    "backoff": "2.4.1",
 | 
					    "backoff": "2.4.1",
 | 
				
			||||||
    "bigspinner": "3.1.0",
 | 
					    "bigspinner": "3.1.0",
 | 
				
			||||||
    "bunyan": "1.5.1",
 | 
					    "bunyan": "1.5.1",
 | 
				
			||||||
    "cmdln": "3.5.2",
 | 
					    "cmdln": "3.5.3",
 | 
				
			||||||
    "extsprintf": "1.0.2",
 | 
					    "extsprintf": "1.0.2",
 | 
				
			||||||
    "lomstream": "1.1.0",
 | 
					    "lomstream": "1.1.0",
 | 
				
			||||||
    "mkdirp": "0.5.1",
 | 
					    "mkdirp": "0.5.1",
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user