Skip to content

Commit 92834fe

Browse files
committed
fix: Update commander API to v12 compatibility
- Migrated from deprecated commander API to v12 Command() pattern - Fixed lib/kms/utilities.js createEncryptedBucket() function - Fixed lib/nfs/utilities.js createBucketWithNFSEnabled() function - Fixed lib/utapi/utilities.js listMetrics() function - Fixed bin/search_bucket.js searchBucket() function Changes: - Replace 'commander.version().option()' with 'new commander.Command()' - Replace direct commander property access with 'program.opts()' - Update all commander.xyz references to program.opts().xyz This fixes TypeError: commander.version is not a function when using create_encrypted_bucket.js and other utilities with commander v12.
1 parent 1e7572a commit 92834fe

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

bin/search_bucket.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ function _performSearch(host,
7878
*/
7979
function searchBucket() {
8080
// TODO: Include other bucket listing possible query params?
81-
commander
81+
const program = new commander.Command();
82+
program
8283
.version('0.0.1')
8384
.option('-a, --access-key <accessKey>', 'Access key id')
8485
.option('-k, --secret-key <secretKey>', 'Secret access key')
@@ -93,11 +94,11 @@ function searchBucket() {
9394
.option('-v, --verbose')
9495
.parse(process.argv);
9596
const { host, port, accessKey, secretKey, sessionToken, bucket, query, listVersions, verbose, ssl } =
96-
commander;
97+
program.opts();
9798

9899
if (!host || !port || !accessKey || !secretKey || !bucket || !query) {
99100
logger.error('missing parameter');
100-
commander.outputHelp();
101+
program.outputHelp();
101102
process.exit(1);
102103
}
103104

lib/kms/utilities.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function _createEncryptedBucket(host,
7272
* @return {undefined}
7373
*/
7474
function createEncryptedBucket() {
75-
commander
75+
const program = new commander.Command();
76+
program
7677
.version('0.0.1')
7778
.option('-a, --access-key <accessKey>', 'Access key id')
7879
.option('-k, --secret-key <secretKey>', 'Secret access key')
@@ -86,11 +87,11 @@ function createEncryptedBucket() {
8687
.parse(process.argv);
8788

8889
const { host, port, accessKey, secretKey, bucket, verbose, ssl,
89-
locationConstraint } = commander;
90+
locationConstraint } = program.opts();
9091

9192
if (!host || !port || !accessKey || !secretKey || !bucket) {
9293
logger.error('missing parameter');
93-
commander.outputHelp();
94+
program.outputHelp();
9495
process.exit(1);
9596
}
9697
_createEncryptedBucket(host, port, bucket, accessKey, secretKey, verbose,

lib/nfs/utilities.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ function _createBucketWithNFSEnabled(host, port, bucketName, accessKey,
6464
* @return {undefined}
6565
*/
6666
function createBucketWithNFSEnabled() {
67-
commander
67+
const program = new commander.Command();
68+
program
6869
.version('0.0.1')
6970
.option('-a, --access-key <accessKey>', 'Access key id')
7071
.option('-k, --secret-key <secretKey>', 'Secret access key')
@@ -78,11 +79,11 @@ function createBucketWithNFSEnabled() {
7879
.parse(process.argv);
7980

8081
const { host, port, accessKey, secretKey, bucket, verbose,
81-
ssl, locationConstraint } = commander;
82+
ssl, locationConstraint } = program.opts();
8283

8384
if (!host || !port || !accessKey || !secretKey || !bucket) {
8485
logger.error('missing parameter');
85-
commander.outputHelp();
86+
program.outputHelp();
8687
process.exit(1);
8788
}
8889
_createBucketWithNFSEnabled(host, port, bucket, accessKey, secretKey,

lib/utapi/utilities.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ function _listMetrics(host,
123123
* @return {undefined}
124124
*/
125125
function listMetrics(metricType) {
126-
commander
126+
const program = new commander.Command();
127+
program
127128
.version('0.0.1')
128129
.option('-a, --access-key <accessKey>', 'Access key id')
129130
.option('-k, --secret-key <secretKey>', 'Secret access key');
@@ -132,11 +133,11 @@ function listMetrics(metricType) {
132133
// bin/list_bucket_metrics.js when prior method of listing bucket metrics is
133134
// no longer supported.
134135
if (metricType === 'buckets') {
135-
commander
136+
program
136137
.option('-b, --buckets <buckets>', 'Name of bucket(s) with ' +
137138
'a comma separator if more than one');
138139
} else {
139-
commander
140+
program
140141
.option('-m, --metric <metric>', 'Metric type')
141142
.option('--buckets <buckets>', 'Name of bucket(s) with a comma ' +
142143
'separator if more than one')
@@ -146,7 +147,7 @@ function listMetrics(metricType) {
146147
'more than one')
147148
.option('--service <service>', 'Name of service');
148149
}
149-
commander
150+
program
150151
.option('-s, --start <start>', 'Start of time range')
151152
.option('-r, --recent', 'List metrics including the previous and ' +
152153
'current 15 minute interval')
@@ -159,7 +160,7 @@ function listMetrics(metricType) {
159160

160161
const { host, port, accessKey, secretKey, start, end, verbose, recent,
161162
ssl } =
162-
commander;
163+
program.opts();
163164
const requiredOptions = { host, port, accessKey, secretKey };
164165
// If not old style bucket metrics, we require usage of the metric option
165166
if (metricType !== 'buckets') {
@@ -174,24 +175,25 @@ function listMetrics(metricType) {
174175
}
175176
}
176177
// If old style bucket metrics, `metricType` will be 'buckets'. Otherwise,
177-
// `commander.metric` should be defined.
178-
const metric = metricType === 'buckets' ? 'buckets' : commander.metric;
179-
requiredOptions[metric] = commander[metric];
178+
// `program.opts().metric` should be defined.
179+
const opts = program.opts();
180+
const metric = metricType === 'buckets' ? 'buckets' : opts.metric;
181+
requiredOptions[metric] = opts[metric];
180182
// If not recent listing, the start option must be provided
181183
if (!recent) {
182-
requiredOptions.start = commander.start;
184+
requiredOptions.start = opts.start;
183185
}
184186
Object.keys(requiredOptions).forEach(option => {
185187
if (!requiredOptions[option]) {
186188
logger.error(`missing required option: ${option}`);
187-
commander.outputHelp();
189+
program.outputHelp();
188190
process.exit(1);
189191
}
190192
});
191193

192-
// The string `commander[metric]` is a comma-separated list of resources
194+
// The string `opts[metric]` is a comma-separated list of resources
193195
// given by the user.
194-
const resources = commander[metric].split(',');
196+
const resources = opts[metric].split(',');
195197

196198
// Validate passed accounts to remove any canonicalIDs
197199
if (metric === 'accounts') {
@@ -208,7 +210,7 @@ function listMetrics(metricType) {
208210
const numStart = Number.parseInt(start, 10);
209211
if (!numStart) {
210212
logger.error('start must be a number');
211-
commander.outputHelp();
213+
program.outputHelp();
212214
process.exit(1);
213215
return;
214216
}
@@ -217,7 +219,7 @@ function listMetrics(metricType) {
217219
const numEnd = Number.parseInt(end, 10);
218220
if (!numEnd) {
219221
logger.error('end must be a number');
220-
commander.outputHelp();
222+
program.outputHelp();
221223
process.exit(1);
222224
return;
223225
}

0 commit comments

Comments
 (0)