Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
retorillo committed Jan 19, 2017
1 parent c96a7cc commit 7cd7367
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,6 @@ Avaiable built-in types are the followings:
- `switch`: `switch` typed option never have its value. Similar to `-f` option
of `rm` command.

## Custom Type

By specifying parser-function instead of type name, can declare the custom typed
option.

```javascript
function parseInterval(val) {
var m =/^([0-9]+)([mh])$/i.exec(val);
if (!m) // Thrown error is set to InvalidValueError.innerError
throw new Error("interval type is expected");
return {
value: parseInt(m[1]);
unit: m[2],
}
}
var optmap = {
date = parseInterval,
}
```

#### Leading tilde before type name

Expand Down Expand Up @@ -137,6 +118,26 @@ gnuopt.parse('-ccccc', { c: '*switch' });
// { c: 5 }
```

## Custom Type

By specifying parser-function instead of type name, can declare the custom typed
option.

```javascript
function parseInterval(val) {
var m =/^([0-9]+)([mh])$/i.exec(val);
if (!m) // Thrown error is set to InvalidValueError.innerError
throw new Error("interval type is expected");
return {
value: parseInt(m[1]);
unit: m[2],
}
}
var optmap = {
date = parseInterval,
}
```

## Errors

The following errors will be thrown when verification is failed.
Expand Down

0 comments on commit 7cd7367

Please sign in to comment.