Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
test(features/commander): Negative numbers don't need =
Browse files Browse the repository at this point in the history
Added "custom option handling" for integer and number.

vercel/arg#52
  • Loading branch information
karfau committed Feb 1, 2020
1 parent b511af7 commit 3e2dcc8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions commander/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const commander = require('commander');
const c = commander
.option('--flag')
.option('--count', 'counts', (_, prev = 0) => prev + 1)
.option('--int <integer>', 'integer', (s) => parseInt(s, 10))
.option('--num <number>', 'number', parseFloat)
.option('--str <val>')
.option('--arr <val>', 'collects', (cur, prev = []) => {
prev.push(cur);
Expand Down
55 changes: 53 additions & 2 deletions commander/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,66 @@
},
"number": {
"$comment": "What are the options for converting values to JS number type?",
"code": {},
"code": {
"node ./dump.js --num 0.5": {
"value": {
"options": {
"num": 0.5
}
}
},
"node ./dump.js --num=-1.0": {
"value": {
"options": {
"num": -1
}
}
},
"node ./dump.js --num -123.5": {
"value": {
"options": {
"num": -123.5
}
}
}
},
"references": [
"https://github.com/tj/commander.js#custom-option-processing",
"https://github.com/karfau/node-cli-arguments-options/issues/6"
]
},
"integer": {
"$comment": "What are the options for converting values to integer values?",
"code": {},
"code": {
"node ./dump.js --int 100": {
"value": {
"options": {
"int": 100
}
}
},
"node ./dump.js --int=-123": {
"value": {
"options": {
"int": -123
}
}
},
"node ./dump.js --int=-5.9": {
"value": {
"options": {
"int": -5
}
}
},
"node ./dump.js --int -123": {
"value": {
"options": {
"int": -123
}
}
}
},
"references": [
"https://github.com/tj/commander.js#custom-option-processing",
"https://github.com/karfau/node-cli-arguments-options/issues/6"
Expand Down

0 comments on commit 3e2dcc8

Please sign in to comment.