-
Notifications
You must be signed in to change notification settings - Fork 42
/
sdc-getmachinetag
executable file
·73 lines (58 loc) · 1.6 KB
/
sdc-getmachinetag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
// -*- mode: js -*-
// vim: set filetype=javascript :
// Copyright 2013 Joyent, Inc. All rights reserved.
var url = require('url');
var common = require('../lib/cli_common');
// --- Globals
var Options = {
'account': String,
'api-version': String,
'debug': Boolean,
'help': Boolean,
'keyId': String,
'tag': String,
'url': url,
'version': Boolean,
'verbose': Boolean,
'user': String,
'role': String
};
var ShortOptions = {
'a': ['--account'],
'd': ['--debug'],
'h': ['--help'],
'?': ['--help'],
'k': ['--keyId'],
't': ['--tag'],
'u': ['--url'],
'v': ['--verbose'],
'A': ['--user']
};
var usageStr = common.buildUsageString(Options) + ' machine_id';
usageStr += common.buildDetailedUsageString(Options, { 'tag': 'tag name' });
// --- Mainline
common.parseArguments(Options, ShortOptions, function (parsed) {
if (!parsed.tag) {
common.usage(usageStr, 1, 'tag required');
}
if (parsed.argv.remain.length < 1) {
common.usage(usageStr, 1, 'machine required');
}
function callback(err, obj) {
if (err) {
if (obj && obj.errors && obj.errors[0]) {
console.error(err.message + ':', obj.errors[0].message);
} else {
console.error(err.message);
}
process.exit(3);
}
common.emit(obj);
common.exit(0);
}
var client = common.newClient(parsed);
parsed.argv.remain.forEach(function (machine) {
client.getMachineTag(machine, parsed.tag, callback);
});
}, usageStr);