Skip to content

Commit

Permalink
Merge pull request #30 from at-grandpa/issue28
Browse files Browse the repository at this point in the history
Fix Issue28
  • Loading branch information
at-grandpa authored Apr 28, 2018
2 parents df6e829 + bd3165c commit e9d2223
Show file tree
Hide file tree
Showing 24 changed files with 1,686 additions and 1,109 deletions.
53 changes: 40 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Add this to your application's `shard.yml`:
dependencies:
clim:
github: at-grandpa/clim
version: 0.2.2
version: 0.3.0
```
## Minimum sample
Expand Down Expand Up @@ -363,18 +363,45 @@ class MyCli < Clim
end
```

If default is not specified, it is nilable.
The type of the option is determined by the `default` and `required` patterns.

```crystal
class MyCli < Clim
main_command do
option "-g WORDS", "--greeting=WORDS", type: String, desc: "Words of greetings."
run do |options, arguments|
puts typeof(options.greeting) # => (String | Nil)
end
end
end
```
*Number*

For example `Int8`.

`default` | `required` | Type
---------|----------|---------
exist | `true` | `Int8` (default: Your specified value.) |
exist | `false` | `Int8` (default: Your specified value.) |
not exist | `true` | `Int8` |
not exist | `false` | `Int8 \| Nil` |

*String*

`default` | `required` | Type
---------|----------|---------
exist | `true` | `String` (default: Your specified value.) |
exist | `false` | `String` (default: Your specified value.) |
not exist | `true` | `String` |
not exist | `false` | `String \| Nil` |

*Bool*

`default` | `required` | Type
---------|----------|---------
exist | `true` | `Bool` (default: Your specified value.) |
exist | `false` | `Bool` (default: Your specified value.) |
not exist | `true` | `Bool` |
not exist | `false` | `Bool` (default: `false`) |

*Array*

`default` | `required` | Type
---------|----------|---------
exist | `true` | `Array(T)` (default: Your specified value.) |
exist | `false` | `Array(T)` (default: Your specified value.) |
not exist | `true` | `Array(T)` |
not exist | `false` | `Array(T)` (default: `[] of T`) |

For Bool, you do not need to specify arguments for short or long.

Expand Down Expand Up @@ -432,4 +459,4 @@ $ make spec

## Contributors

- [at-grandpa](https://github.com/at-grandpa) at-grandpa - creator, maintainer
- [at-grandpa](https://github.com/at-grandpa) - creator, maintainer
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: clim
version: 0.2.2
version: 0.3.0

authors:
- at-grandpa <@at_grandpa>
Expand Down
2 changes: 1 addition & 1 deletion spec/clim/dsl_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "./../spec_helper"
macro assert_opts_and_args(spec_case)
opts.help.should eq {{spec_case["expect_help"]}}
{% if spec_case.keys.includes?("expect_opts".id) %}
opts.{{spec_case["expect_opts"]["method"].id}}.is_a?({{spec_case["expect_opts"]["type"]}}).should be_true
typeof(opts.{{spec_case["expect_opts"]["method"].id}}).should eq {{spec_case["expect_opts"]["type"]}}
opts.{{spec_case["expect_opts"]["method"].id}}.should eq {{spec_case["expect_opts"]["expect_value"]}}
{% end %}
args.should eq {{spec_case["expect_args"]}}
Expand Down
Loading

0 comments on commit e9d2223

Please sign in to comment.