display default values in `--help options` (#2018)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 28 May 2017 14:57:20 +0000 (22:57 +0800)
committerGitHub <noreply@github.com>
Sun, 28 May 2017 14:57:20 +0000 (22:57 +0800)
README.md
bin/uglifyjs

index 985fe50..d7e65b2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -45,6 +45,7 @@ a double dash to prevent input files being used as option arguments:
 
 ```
     -h, --help                  Print usage information.
+                                `--help options` for details on available options.
     -V, --version               Print version number.
     -p, --parse <options>       Specify parser options:
                                 `acorn`  Use Acorn for parsing.
@@ -713,14 +714,14 @@ UglifyJS.minify(code, { mangle: { toplevel: true } }).code;
 
 ### Mangle properties options
 
-- `reserved` (default: `[]`) -- Do not mangle property names listed in the 
+- `reserved` (default: `[]`) -- Do not mangle property names listed in the
   `reserved` array.
 - `regex` (default: `null`) -— Pass a RegExp literal to only mangle property
   names matching the regular expression.
 - `keep_quoted` (default: `false`) -— Only mangle unquoted property names.
 - `debug` (default: `false`) -— Mangle names with the original name still present.
   Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
-- `builtins` (default: `false`) -- Use `true` to allow the mangling of builtin 
+- `builtins` (default: `false`) -- Use `true` to allow the mangling of builtin
   DOM properties. Not recommended to override this setting.
 
 ## Output options
index b9406e1..a2039f7 100755 (executable)
@@ -21,7 +21,7 @@ var options = {
     compress: false,
     mangle: false
 };
-program.version(info.name + ' ' + info.version);
+program.version(info.name + " " + info.version);
 program.parseArgv = program.parse;
 program.parse = undefined;
 if (process.argv.indexOf("ast") >= 0) program.helpInformation = UglifyJS.describe_ast;
@@ -30,8 +30,13 @@ else if (process.argv.indexOf("options") >= 0) program.helpInformation = functio
     var options = UglifyJS.default_options();
     for (var option in options) {
         text.push("--" + (option == "output" ? "beautify" : option == "sourceMap" ? "source-map" : option) + " options:");
-        Object.keys(options[option]).forEach(function(name) {
-            text.push("  " + name);
+        var defs = options[option];
+        var padding = "";
+        Object.keys(defs).map(function(name) {
+            if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
+            return [ name, JSON.stringify(defs[name]) ];
+        }).forEach(function(tokens) {
+            text.push("  " + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
         });
         text.push("");
     }