From e62b879b488f40acd4e7e95d70c53a91c45810ed Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 28 May 2017 22:57:20 +0800 Subject: [PATCH] display default values in `--help options` (#2018) --- README.md | 5 +++-- bin/uglifyjs | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 985fe507..d7e65b27 100644 --- 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 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 diff --git a/bin/uglifyjs b/bin/uglifyjs index b9406e1c..a2039f7e 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -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(""); } -- 2.34.1