Skip to content

Commit

Permalink
CLI: Renamed --strict-long/message to --force-long/message with backw…
Browse files Browse the repository at this point in the history
…ard compatible aliases, see #741
  • Loading branch information
dcodeIO committed Apr 3, 2017
1 parent 6aae71f commit 007b232
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
60 changes: 37 additions & 23 deletions cli/pbjs.js
Expand Up @@ -23,37 +23,47 @@ exports.main = function main(args, callback) {
var lintDefault = "eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins";
var argv = minimist(args, {
alias: {
target : "t",
out : "o",
path : "p",
wrap : "w",
root : "r",
lint : "l"
target: "t",
out: "o",
path: "p",
wrap: "w",
root: "r",
lint: "l",
// backward compatibility:
"force-long": "strict-long",
"force-message": "strict-message"
},
string: [ "target", "out", "path", "wrap", "root", "lint" ],
boolean: [ "keep-case", "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse", "strict-long", "strict-message" ],
boolean: [ "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments", "es6", "sparse", "keep-case", "force-long", "force-message" ],
default: {
target : "json",
create : true,
encode : true,
decode : true,
verify : true,
convert : true,
delimited : true,
beautify : true,
comments : true,
es6 : null,
lint : lintDefault,
"keep-case" : false,
"strict-long" : false,
"strict-message": false
target: "json",
create: true,
encode: true,
decode: true,
verify: true,
convert: true,
delimited: true,
beautify: true,
comments: true,
es6: null,
lint: lintDefault,
"keep-case": false,
"force-long": false,
"force-message": false
}
});

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

// alias hyphen args in camel case
Object.keys(argv).forEach(function(key) {
var camelKey = key.replace(/\-([a-z])/g, function($0, $1) { return $1.toUpperCase(); });
if (camelKey !== key)
argv[camelKey] = argv[key];
});

// protobuf.js package directory contains additional, otherwise non-bundled google types
paths.push(path.relative(process.cwd(), path.join(__dirname, "..")) || ".");

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

if (typeof argv["strict-long"] === "boolean")
argv["force-long"] = argv["strict-long"];

// Resolve glob expressions
for (var i = 0; i < files.length;) {
if (glob.hasMagic(files[i])) {
Expand Down
8 changes: 4 additions & 4 deletions cli/targets/static.js
Expand Up @@ -313,7 +313,7 @@ function toJsType(field) {
case "sint64":
case "fixed64":
case "sfixed64":
type = config["strict-long"] ? "Long" : "number|Long";
type = config.forceLong ? "Long" : "number|Long";
break;
case "bool":
type = "boolean";
Expand All @@ -328,7 +328,7 @@ function toJsType(field) {
if (field.resolve().resolvedType instanceof Enum)
type = field.resolvedType.fullName.substring(1); // reference the enum
else if (field.resolvedType instanceof Type)
type = field.resolvedType.fullName.substring(1) + (config["strict-message"] ? "" : "$Properties"); // reference the typedef
type = field.resolvedType.fullName.substring(1) + (config.forceMessage ? "" : "$Properties"); // reference the typedef
else
type = "*"; // should not happen
break;
Expand Down Expand Up @@ -441,7 +441,7 @@ function buildType(ref, type) {
push("");
pushComment([
"Encodes the specified " + type.name + " message. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
"@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
"@param {" + fullName + (config.forceMessage ? "" : "$Properties") + "} " + (config.beautify ? "message" : "m") + " " + type.name + " message or plain object to encode",
"@param {$protobuf.Writer} [" + (config.beautify ? "writer" : "w") + "] Writer to encode to",
"@returns {$protobuf.Writer} Writer"
]);
Expand All @@ -451,7 +451,7 @@ function buildType(ref, type) {
push("");
pushComment([
"Encodes the specified " + type.name + " message, length delimited. Does not implicitly {@link " + fullName + ".verify|verify} messages.",
"@param {" + fullName + (config["strict-message"] ? "" : "$Properties") + "} message " + type.name + " message or plain object to encode",
"@param {" + fullName + (config.forceMessage ? "" : "$Properties") + "} message " + type.name + " message or plain object to encode",
"@param {$protobuf.Writer} [writer] Writer to encode to",
"@returns {$protobuf.Writer} Writer"
]);
Expand Down

0 comments on commit 007b232

Please sign in to comment.