Skip to content

Commit

Permalink
Merge pull request #4 from Techniv/master
Browse files Browse the repository at this point in the history
v1.2.0 stable
  • Loading branch information
Techniv committed Dec 3, 2015
2 parents 5585fdb + ecefaf9 commit 1673512
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.settings
/nbproject
/.svn
*.iml
4 changes: 4 additions & 0 deletions CHANGELOGS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
## 1.2.0
- Add '''forceString''' boolean option to force keep the string value (not parse int/float).
- Add some doc.

## 1.1.0
- Add static configuration items.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ server.js
defaultValue: 85 // If the parameter not given, use the default value;
},

verbose:{
verbose:{ // If key is not define, the name is used instead
shortKey: 'v',
action: 'set', // Set a static value
value: true // The value to set
Expand All @@ -39,6 +39,14 @@ server.js
},

staticString: 'foo bar'

serial:{
shortKey: 's',
action: 'get',
number: 1
forceString: true // Disable the parser to force a string value instead of an integer.
defaultValue: "00561"
}
});

var params = cmdConf.getParameters();
Expand All @@ -48,7 +56,11 @@ server.js
```

If you give a simple string to the `configure()` method, witch represent the path of
a JSON file, cmd-conf try to resolve path and load config from this file.
a JSON file, cmd-conf try to resolve path and load config from this file. If you not
pass argument, cmd-conf try to get the configuration to the `config.json` file.

If you call `getParameters()` before `configure()`, the configuration method wil be
automatically fired.


-----------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions libs/cmd-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function cmdConf(cmd){
var action = option.action;
switch(action){
case 'get':
var params = getCmdParam(option.position+1, option.number, args);
var params = getCmdParam(option.position+1, option.number, args, option.forceString);
setParam(name,params);
break;
case 'set':
Expand All @@ -197,14 +197,14 @@ function cmdConf(cmd){
}
}

function getCmdParam(start, num, args){
function getCmdParam(start, num, args, forceString){
var params = args.slice(start,start+num);
var assign = [];
for(var i in params){
var param = params[i];
if(/^-{1,2}/.test(param)) break;
else{
if(/^[0-9]+(?:(\.)[0-9]+)?$/.test(param)){
if(!forceString && /^[0-9]+(?:(\.)[0-9]+)?$/.test(param)){
params[i] = (RegExp.$1 == '.')? parseFloat(param) : parseInt(param);
}
assign.push(params[i]);
Expand Down

0 comments on commit 1673512

Please sign in to comment.