Skip to content

Commit cc55fd1

Browse files
committed
Fix CLI tests
1 parent aea5fdd commit cc55fd1

6 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/bin/apply.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ main = function (argv) {
5353
}
5454
};
5555

56+
// Commander v7+ no longer exposes options as direct properties by default
57+
// (it prefers `program.opts()`), but this CLI and its tests read `program.projectName`,
58+
// `program.target`, etc. Keep the legacy access pattern for backwards compatibility.
59+
program.storeOptionsAsProperties();
60+
5661
program
5762
.version('0.2.0')
63+
.argument('<patch-file>', 'Path to patch json file')
5864
.usage('<patch-file> [options]')
5965
.option('-m, --mongo-database-uri [url]',
6066
'URI of the MongoDB [by default we use the one from the configuration file]')
@@ -63,7 +69,15 @@ main = function (argv) {
6369
.option('-o, --owner [string]', 'the owner of the project [by default, the user is the owner]')
6470
.option('-t, --target [branch/commit]', 'the target where we should apply the patch [mandatory]')
6571
.option('-n, --no-update', 'show if we should not update the branch [by default it is false]')
66-
.parse(argv);
72+
.exitOverride();
73+
74+
try {
75+
program.parse(argv);
76+
} catch (e) {
77+
program.outputHelp();
78+
mainDeferred.reject(new SyntaxError('invalid argument'));
79+
return mainDeferred.promise;
80+
}
6781

6882
if (program.mongoDatabaseUri) {
6983
// this line throws a TypeError for invalid databaseConnectionString

src/bin/diff.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ main = function (argv) {
5151
},
5252
badArgument = false;
5353

54+
program.storeOptionsAsProperties();
55+
5456
program
5557
.version('0.2.0')
5658
.option('-m, --mongo-database-uri [url]',

src/bin/export.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ main = function (argv) {
4848
program = new Command(),
4949
syntaxFailure = false;
5050

51+
program.storeOptionsAsProperties();
52+
5153
gmeConfig = require(path.join(process.cwd(), 'config'));
5254
logger = webgme.Logger.create('gme:bin:export', gmeConfig.bin.log, false);
5355
blobClient = new FSBlobClient(gmeConfig, logger.fork('BlobClient'));

src/bin/import.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ main = function (argv) {
110110
}
111111
};
112112

113+
program.storeOptionsAsProperties();
114+
113115
program
114116
.version('1.7.2')
117+
.argument('<project-package-file>', 'Path to exported webgmex package')
115118
.usage('<project-package-file> [options]')
116119
.option('-m, --mongo-database-uri [url]',
117120
'URI of the MongoDB [by default we use the one from the configuration file]')
@@ -122,7 +125,15 @@ main = function (argv) {
122125
'the branch that should be created with the imported data [by default it is the \'master\']')
123126
.option('-w --overwrite [boolean]', 'if a project exist it will be deleted and created again')
124127
.option('-c --commit [string]', 'if given, the import will be a descendant of it')
125-
.parse(argv);
128+
.exitOverride();
129+
130+
try {
131+
program.parse(argv);
132+
} catch (e) {
133+
program.outputHelp();
134+
mainDeferred.reject(new SyntaxError('invalid argument'));
135+
return mainDeferred.promise;
136+
}
126137

127138
if (program.mongoDatabaseUri) {
128139
// this line throws a TypeError for invalid databaseConnectionString

src/bin/merge.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var main = function (argv) {
2727
syntaxFailure = false;
2828

2929
logger.debug(argv);
30+
program.storeOptionsAsProperties();
3031
program
3132
.version('0.2.0')
3233
.option('-m, --mongo-database-uri [url]',

src/bin/run_plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ main = function (argv, callback) {
3939
}
4040

4141
webgme.addToRequireJsPaths(gmeConfig);
42+
program.storeOptionsAsProperties();
4243
program
4344
.version('2.2.0')
44-
.arguments('<pluginName> <projectName>')
45+
.arguments('[pluginName] [projectName]')
4546
.option('-b, --branchName [string]', 'Name of the branch to load and save to.', 'master')
4647
.option('-c, --commitHash [string]', 'Commit hash to run from, if set branch will only be used for update.')
4748
.option('-a, --activeNode [string]', 'ID/Path to active node.', '')

0 commit comments

Comments
 (0)