improve CLI usability (#2016)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 27 May 2017 20:09:40 +0000 (04:09 +0800)
committerGitHub <noreply@github.com>
Sat, 27 May 2017 20:09:40 +0000 (04:09 +0800)
Report supported options upon invalid option syntax.

fixes #1883

bin/uglifyjs
test/mocha/cli.js

index 8ea7d16..158dc57 100755 (executable)
@@ -351,7 +351,7 @@ function parse_js(flag, constants) {
                 }
             }));
         } catch(ex) {
-            fatal("Error parsing arguments for '" + flag + "': " + value);
+            options[value] = null;
         }
         return options;
     }
index 565b606..4234f2f 100644 (file)
@@ -537,4 +537,13 @@ describe("bin/uglifyjs", function () {
             done();
         });
     });
+    it("Should print supported options on invalid option syntax", function(done) {
+        var command = uglifyjscmd + " test/input/comments/filter.js -b ascii-only";
+        exec(command, function (err, stdout, stderr) {
+            assert.ok(err);
+            assert.strictEqual(stdout, "");
+            assert.ok(/^Supported options:\n\{[^}]+}\nERROR: `ascii-only` is not a supported option/.test(stderr), stderr);
+            done();
+        });
+    });
 });