Skip to content

Commit 007b232

Browse files
committed
CLI: Renamed --strict-long/message to --force-long/message with backward compatible aliases, see #741
1 parent 6aae71f commit 007b232

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

cli/pbjs.js

+37-23
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,47 @@ exports.main = function main(args, callback) {
2323
var lintDefault = "eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins";
2424
var argv = minimist(args, {
2525
alias: {
26-
target : "t",
27-
out : "o",
28-
path : "p",
29-
wrap : "w",
30-
root : "r",
31-
lint : "l"
26+
target: "t",
27+
out: "o",
28+
path: "p",
29+
wrap: "w",
30+
root: "r",
31+
lint: "l",
32+
// backward compatibility:
33+
"force-long": "strict-long",
34+
"force-message": "strict-message"
3235
},
3336
string: [ "target", "out", "path", "wrap", "root", "lint" ],
34-
boolean: [ "keep-case", "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse", "strict-long", "strict-message" ],
37+
boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse", "keep-case", "force-long", "force-message" ],
3538
default: {
36-
target : "json",
37-
create : true,
38-
encode : true,
39-
decode : true,
40-
verify : true,
41-
convert : true,
42-
delimited : true,
43-
beautify : true,
44-
comments : true,
45-
es6 : null,
46-
lint : lintDefault,
47-
"keep-case" : false,
48-
"strict-long" : false,
49-
"strict-message": false
39+
target: "json",
40+
create: true,
41+
encode: true,
42+
decode: true,
43+
verify: true,
44+
convert: true,
45+
delimited: true,
46+
beautify: true,
47+
comments: true,
48+
es6: null,
49+
lint: lintDefault,
50+
"keep-case": false,
51+
"force-long": false,
52+
"force-message": false
5053
}
5154
});
5255

5356
var target = targets[argv.target],
5457
files = argv._,
5558
paths = typeof argv.path === "string" ? [ argv.path ] : argv.path || [];
5659

60+
// alias hyphen args in camel case
61+
Object.keys(argv).forEach(function(key) {
62+
var camelKey = key.replace(/\-([a-z])/g, function($0, $1) { return $1.toUpperCase(); });
63+
if (camelKey !== key)
64+
argv[camelKey] = argv[key];
65+
});
66+
5767
// protobuf.js package directory contains additional, otherwise non-bundled google types
5868
paths.push(path.relative(process.cwd(), path.join(__dirname, "..")) || ".");
5969

@@ -110,15 +120,19 @@ exports.main = function main(args, callback) {
110120
" --no-delimited Does not generate delimited encode/decode functions.",
111121
" --no-beautify Does not beautify generated code.",
112122
" --no-comments Does not output any JSDoc comments.",
113-
" --strict-long Strictly references 'Long' for s-/u-/int64 and s-/fixed64 types.",
114-
" --strict-message Strictly references message types instead of typedefs.",
123+
"",
124+
" --force-long Enfores the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.",
125+
" --force-message Enfores the use of runtime messages instead of plain objects.",
115126
"",
116127
"usage: " + chalk.bold.green("pbjs") + " [options] file1.proto file2.json ..." + chalk.gray(" (or) ") + "other | " + chalk.bold.green("pbjs") + " [options] -",
117128
""
118129
].join("\n"));
119130
return 1;
120131
}
121132

133+
if (typeof argv["strict-long"] === "boolean")
134+
argv["force-long"] = argv["strict-long"];
135+
122136
// Resolve glob expressions
123137
for (var i = 0; i < files.length;) {
124138
if (glob.hasMagic(files[i])) {

cli/targets/static.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function toJsType(field) {
313313
case "sint64":
314314
case "fixed64":
315315
case "sfixed64":
316-
type = config["strict-long"] ? "Long" : "number|Long";
316+
type = config.forceLong ? "Long" : "number|Long";
317317
break;
318318
case "bool":
319319
type = "boolean";
@@ -328,7 +328,7 @@ function toJsType(field) {
328328
if (field.resolve().resolvedType instanceof Enum)
329329
type = field.resolvedType.fullName.substring(1); // reference the enum
330330
else if (field.resolvedType instanceof Type)
331-
type = field.resolvedType.fullName.substring(1) + (config["strict-message"] ? "" : "$Properties"); // reference the typedef
331+
type = field.resolvedType.fullName.substring(1) + (config.forceMessage ? "" : "$Properties"); // reference the typedef
332332
else
333333
type = "*"; // should not happen
334334
break;
@@ -441,7 +441,7 @@ function buildType(ref, type) {
441441
push("");
442442
pushComment([
443443
"Encodes the specified " + type.name + " message. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
444-
"@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
444+
"@param {" + fullName + (config.forceMessage ? "" : "$Properties") + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
445445
"@param {$protobuf.Writer} [" + (config.beautify ? "writer" : "w") + "] Writer to encode to",
446446
"@returns {$protobuf.Writer} Writer"
447447
]);
@@ -451,7 +451,7 @@ function buildType(ref, type) {
451451
push("");
452452
pushComment([
453453
"Encodes the specified " + type.name + " message, length delimited. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
454-
"@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} message " + type.name + " message or plain object to encode",
454+
"@param {" + fullName + (config.forceMessage ? "" : "$Properties") + "} message " + type.name + " message or plain object to encode",
455455
"@param {$protobuf.Writer} [writer] Writer to encode to",
456456
"@returns {$protobuf.Writer} Writer"
457457
]);

0 commit comments

Comments
 (0)