Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
at-grandpa committed Jul 29, 2017
1 parent 25bfd65 commit 626744a
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ require "clim"

#### string

Short option and Long option.

```crystal
string "-s ARG", "--string-long-name=ARG", desc: "Option description." # String option
run do |opts, args|
Expand All @@ -259,22 +257,8 @@ Short option and Long option.
end
```

Short option only.

```crystal
string "-s ARG", desc: "Option description." # String option
run do |opts, args|
puts opts["s"] # => print your option value.
puts typeof(opts["s"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["s"].as(String)) # => String
# puts opts["string-long-name"] # => ERROR: Missing hash key: "string-long-name"
end
```

#### bool

Short option and Long option.

```crystal
bool "-b", "--bool-long-name", desc: "Option description." # Bool option
run do |opts, args|
Expand All @@ -285,41 +269,58 @@ Short option and Long option.
end
```

Short option only.
#### array

```crystal
bool "-b", desc: "Option description." # Bool option
array "-a ITEM", "--array-long-name=ITEM", desc: "Option description." # Array option
run do |opts, args|
puts opts["b"] # => print your option value.
puts typeof(opts["b"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["b"].as(Bool)) # => Bool
# puts opts["bool-long-name"] # => ERROR: Missing hash key: "bool-long-name"
puts opts["array-long-name"] # => print your option value.
puts typeof(opts["array-long-name"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["array-long-name"].as(Array(String))) # => Array(String)
# puts opts["a"] # => ERROR: Missing hash key: "a"
end
```

#### array
### Option name

You can specify short name, long name or both.

see: [https://crystal-lang.org/api/0.23.0/OptionParser.html](https://crystal-lang.org/api/0.23.0/OptionParser.html)

Short option and Long option.
#### Short name only

```crystal
array "-a ITEM", "--array-long-name=ITEM", desc: "Option description." # Array option
string "-s ARG", desc: "Option description." # String option
run do |opts, args|
puts opts["array-long-name"] # => print your option value.
puts typeof(opts["array-long-name"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["array-long-name"].as(Array(String))) # => Array(String)
# puts opts["a"] # => ERROR: Missing hash key: "a"
puts opts["s"] # => print your option value.
puts typeof(opts["s"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["s"].as(String)) # => String
# puts opts["string-long-name"] # => ERROR: Missing hash key: "string-long-name"
end
```

#### Long name only

```crystal
string "--string=ARG", desc: "Option description." # String option
run do |opts, args|
puts opts["string"] # => print your option value.
puts typeof(opts["string"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["string"].as(String)) # => String
# puts opts["s"] # => ERROR: Missing hash key: "s"
end
```

Short option only.

#### Both

```crystal
array "-a ITEM", desc: "Option description." # Array option
string "-s ARG", "--string-long-name=ARG", desc: "Option description." # String option
run do |opts, args|
puts opts["a"] # => print your option value.
puts typeof(opts["a"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["a"].as(Array(String))) # => Array(String)
# puts opts["array-long-name"] # => ERROR: Missing hash key: "array-long-name"
puts opts["string-long-name"] # => print your option value.
puts typeof(opts["string-long-name"]) # => (Array(String) | Bool | String | Nil)
puts typeof(opts["string-long-name"].as(String)) # => String
# puts opts["s"] # => ERROR: Missing hash key: "s"
end
```

Expand Down

0 comments on commit 626744a

Please sign in to comment.