Skip to content

Commit

Permalink
Improve help and validation of -calc command
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Nov 17, 2014
1 parent 30298f5 commit bd88abc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
21 changes: 12 additions & 9 deletions mapshaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13594,12 +13594,6 @@ function validateLinesOpts(cmd) {
}
}

function validatePointsOpts(cmd) {
if (cmd._.length > 0) {
error("unknown argument:", cmd._[0]);
}
}


function validateInnerLinesOpts(cmd) {
if (cmd._.length > 0) {
Expand Down Expand Up @@ -14064,7 +14058,11 @@ MapShaper.getOptionParser = function() {

parser.command("points")
.describe("create a point layer from data fields")
.validate(validatePointsOpts)
.validate(function (cmd) {
if (cmd._.length > 0) {
error("unknown argument:", cmd._[0]);
}
})
.option("x", {
describe: "field containing x coordinate"
})
Expand Down Expand Up @@ -14133,10 +14131,15 @@ MapShaper.getOptionParser = function() {
parser.command("calc")
.title("\nInformational commands")
.describe("perform calculations on a data layer, print the result")
.validate(validateExpressionOpts)
.validate(function(cmd) {
if (cmd._.length === 0) {
error("missing a JS expression");
}
validateExpressionOpts(cmd);
})
.option("expression", {
label: "<expression>",
describe: "JS expression to apply to target features"
describe: "some functions: sum() average() median() max() min() count()"
})
.option("where", {
describe: "use a JS expression to select a subset of features"
Expand Down
6 changes: 0 additions & 6 deletions src/cli/mapshaper-option-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ function validateLinesOpts(cmd) {
}
}

function validatePointsOpts(cmd) {
if (cmd._.length > 0) {
error("unknown argument:", cmd._[0]);
}
}


function validateInnerLinesOpts(cmd) {
if (cmd._.length > 0) {
Expand Down
15 changes: 12 additions & 3 deletions src/cli/mapshaper-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,11 @@ MapShaper.getOptionParser = function() {

parser.command("points")
.describe("create a point layer from data fields")
.validate(validatePointsOpts)
.validate(function (cmd) {
if (cmd._.length > 0) {
error("unknown argument:", cmd._[0]);
}
})
.option("x", {
describe: "field containing x coordinate"
})
Expand Down Expand Up @@ -431,10 +435,15 @@ MapShaper.getOptionParser = function() {
parser.command("calc")
.title("\nInformational commands")
.describe("perform calculations on a data layer, print the result")
.validate(validateExpressionOpts)
.validate(function(cmd) {
if (cmd._.length === 0) {
error("missing a JS expression");
}
validateExpressionOpts(cmd);
})
.option("expression", {
label: "<expression>",
describe: "JS expression to apply to target features"
describe: "some functions: sum() average() median() max() min() count()"
})
.option("where", {
describe: "use a JS expression to select a subset of features"
Expand Down

0 comments on commit bd88abc

Please sign in to comment.