clino 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -5
- data/lib/clino/domain/input_parser.rb +0 -7
- data/lib/clino/domain/signature/cli_signature.rb +0 -1
- data/lib/clino/interfaces/cli.rb +1 -2
- data/lib/clino/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5da44c716b390337107099e942d034e182f87d0c201db938ce33edb25afec00
|
4
|
+
data.tar.gz: aab08f2034e3334083e04f85073a7e3762eaa095a64c5514107e3ddb5899a4e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0a9cb88be968997e96874262e24adb6a6d005babec72d6c797ba6871f5f0f1cfc6d76dffd3a2fc05ac4a88d10ab5182d468a80f746dfdfcebc3622122952e09
|
7
|
+
data.tar.gz: 65354f82b88c9bf681233a6e062aa7c83b848f09c6866f1c3dc51ce48352f707d8699834363ca604d69102b291adecd6f9220fe6526e0ff7a8d13801c3079d2e
|
data/README.md
CHANGED
@@ -6,12 +6,20 @@ It is inspired by the [Thor](https://github.com/rails/thor) and [Typer](https://
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Install this gem as a regular gem:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install clino
|
13
|
+
```
|
14
|
+
|
15
|
+
or add this line to your application's Gemfile:
|
10
16
|
|
11
17
|
```ruby
|
12
18
|
gem 'clino'
|
13
19
|
```
|
14
20
|
|
21
|
+
Link: [RubyGems](https://rubygems.org/gems/clino)
|
22
|
+
|
15
23
|
## Usage
|
16
24
|
|
17
25
|
### Interfaces
|
@@ -164,7 +172,9 @@ Unfortunately, ruby doesn't allow inspecting the method's signature default valu
|
|
164
172
|
|
165
173
|
#### Randomizer Advanced Example
|
166
174
|
|
167
|
-
Let's write an advanced version of the randomizer that has CLI signature.
|
175
|
+
Let's write an advanced version of the randomizer that has CLI signature.
|
176
|
+
|
177
|
+
Our entry point is the `run` method, which is called with the parsed and validated input.
|
168
178
|
|
169
179
|
```ruby
|
170
180
|
# randomizer.rb
|
@@ -210,7 +220,7 @@ RandomGeneratorCLI.new.start
|
|
210
220
|
Run the script with the following command:
|
211
221
|
|
212
222
|
```bash
|
213
|
-
ruby randomizer.rb 1 2 --alg uni --i
|
223
|
+
ruby randomizer.rb 1 2 --alg uni --i # => some number from [1.0, 2.0]
|
214
224
|
```
|
215
225
|
|
216
226
|
Get help with the following command:
|
@@ -247,7 +257,7 @@ Options:
|
|
247
257
|
# Algorithm to use (uni or exp)
|
248
258
|
--alg (-a) [string]
|
249
259
|
# Include upper bound
|
250
|
-
[--
|
260
|
+
[--incl] (-i) [bool] [default: false]
|
251
261
|
|
252
262
|
Usage: randomizer.rb [arguments] [options]
|
253
263
|
Use --h, --help to print this help message.
|
@@ -316,7 +326,6 @@ Use --h, --help to print this help message.
|
|
316
326
|
- [ ] Add CI/CD
|
317
327
|
- [ ] Add more examples
|
318
328
|
- [ ] Create a proper documentation
|
319
|
-
- [ ] Better boolean flag handling
|
320
329
|
|
321
330
|
## Contributing
|
322
331
|
|
@@ -22,14 +22,7 @@ module InputParser
|
|
22
22
|
OptionParser.new do |opt|
|
23
23
|
signature.opts.each_key do |name|
|
24
24
|
signature_opt = signature.opts[name]
|
25
|
-
type = signature_opt.type
|
26
25
|
aliases = signature_opt.aliases
|
27
|
-
if type == :bool
|
28
|
-
opt.on(*aliases, "--[no-]#{name}") do |v|
|
29
|
-
input[name] = v
|
30
|
-
end
|
31
|
-
next
|
32
|
-
end
|
33
26
|
|
34
27
|
if signature_opt.required?
|
35
28
|
opt.on(*aliases, "--#{name} #{name.upcase}") do |v|
|
@@ -49,7 +49,6 @@ class CliSignature
|
|
49
49
|
unless @opts.empty?
|
50
50
|
@help += "\nOptions:\n"
|
51
51
|
@opts.each do |name, option|
|
52
|
-
name = "[no-]#{name}" if option.type == :bool
|
53
52
|
opt_part = " #{option.required? ? "--#{name}" : "[--#{name}]"}"
|
54
53
|
if option.aliases && !option.aliases.empty?
|
55
54
|
aliases = option.aliases.join(", ")
|
data/lib/clino/interfaces/cli.rb
CHANGED
@@ -16,8 +16,7 @@ class Cli
|
|
16
16
|
|
17
17
|
def opt(name, type: :string, desc: nil, aliases: [], default: :none)
|
18
18
|
@opt_buffer ||= {}
|
19
|
-
|
20
|
-
aliases = aliases.map { |a| "-#{bool_prefix}#{general_strip a, "-"}" }
|
19
|
+
aliases = aliases.map { |a| "--#{general_strip a, "-"}" }
|
21
20
|
default = load_input type, default unless default == :none
|
22
21
|
@opt_buffer[name] = Base::OptSignature.new(name: name, type: type, default: default, desc: desc,
|
23
22
|
aliases: aliases)
|
data/lib/clino/version.rb
CHANGED