thor-addons 0.1.3 → 0.1.4
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/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +11 -0
- data/README.md +81 -0
- data/lib/thor_addons/options.rb +2 -2
- data/lib/thor_addons/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecbce51975324beec95b2ec8bbd5c4a0d7272beb
|
4
|
+
data.tar.gz: 65ff6886d60b046be49187208c4f53b2f1608827
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb0497cde13470f94d69ab3b337cfc96aaa0942305992295afcad8ca0a99130668a2f2225b93d92ebe5c6b504bc18299d0d5d4111f7ec1baa056aed7ff633d1f
|
7
|
+
data.tar.gz: a7a78ecf49cb710dbdb7629e2f18aebd259ea44af3b57ebb48def44e9886facb0b621266648f99d31753f981c8e4130836a650fd890117e12ad98b0fcea431b3
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
### Pull Requests
|
2
|
+
|
3
|
+
Here are some reasons why a pull request may not be merged:
|
4
|
+
|
5
|
+
1. It hasn’t been reviewed.
|
6
|
+
2. It doesn’t include specs for new functionality.
|
7
|
+
3. It doesn’t include documentation for new functionality.
|
8
|
+
4. It changes behavior without changing the relevant documentation, comments, or specs.
|
9
|
+
5. It changes behavior of an existing public API, breaking backward compatibility.
|
10
|
+
6. It breaks the tests on a supported platform.
|
11
|
+
7. It doesn’t merge cleanly (requiring Git rebasing and conflict resolution).
|
data/README.md
CHANGED
@@ -4,3 +4,84 @@
|
|
4
4
|
[](http://badge.fury.io/rb/thor-addons)
|
5
5
|
|
6
6
|
Extend [Thor](https://github.com/erikhuda/thor) with useful Add-ons
|
7
|
+
|
8
|
+
### Installation
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install thor-addons
|
12
|
+
```
|
13
|
+
|
14
|
+
### Usage
|
15
|
+
|
16
|
+
#### Options
|
17
|
+
|
18
|
+
The `Options` module allows you to read the CLI options from a configuration file or/and environment variables.
|
19
|
+
|
20
|
+
|
21
|
+
include the Options module to your Thor class.
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'thor'
|
25
|
+
require 'thor_addons'
|
26
|
+
|
27
|
+
class CLI < Thor
|
28
|
+
include ThorAddons::Options
|
29
|
+
|
30
|
+
class_option :config_file, type: :string, default: "config.yml", desc: "Configuration file for the CLI"
|
31
|
+
|
32
|
+
method_option :bar, type: :string, default: "biz", desc: "some option"
|
33
|
+
desc "foo", "install one of the available apps"
|
34
|
+
def foo
|
35
|
+
# code
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
In the example above the `--bar` option will be read from the configuration file `--config-file`
|
41
|
+
|
42
|
+
```
|
43
|
+
foo:
|
44
|
+
bar: "zip"
|
45
|
+
```
|
46
|
+
|
47
|
+
and via the environment variable `BAR`
|
48
|
+
|
49
|
+
if you want to disable the configuration file you need to set in your class
|
50
|
+
|
51
|
+
```
|
52
|
+
def with_config_file?
|
53
|
+
false
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
and for disabling the environment variables
|
58
|
+
|
59
|
+
```
|
60
|
+
def with_env?
|
61
|
+
false
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
you can also have environment variables aliases, by setting
|
66
|
+
|
67
|
+
```
|
68
|
+
def envs_aliases
|
69
|
+
{ "BAR" => "MY_BAR" }
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
The cli will set bar with the value of `BAR` or `MY_BAR` if `BAR` is not set.
|
74
|
+
|
75
|
+
This module will set the options in this order: cli options, config file, environment variables
|
76
|
+
|
77
|
+
### Contributing
|
78
|
+
|
79
|
+
If you would like to help, please read the [CONTRIBUTING][] file for suggestions.
|
80
|
+
|
81
|
+
[contributing]: CONTRIBUTING.md
|
82
|
+
|
83
|
+
### License
|
84
|
+
|
85
|
+
Released under the MIT License. See the [LICENSE][] file for further details.
|
86
|
+
|
87
|
+
[license]: LICENSE.md
|
data/lib/thor_addons/options.rb
CHANGED
@@ -95,7 +95,7 @@ module ThorAddons
|
|
95
95
|
|
96
96
|
def add_defaults(hash)
|
97
97
|
hash.inject({}) do |memo, (k, v)|
|
98
|
-
memo[k] = v.nil? ? defaults[k] : v
|
98
|
+
memo[k] = v.nil? ? defaults[k.to_sym] : v
|
99
99
|
|
100
100
|
memo
|
101
101
|
end
|
@@ -103,7 +103,7 @@ module ThorAddons
|
|
103
103
|
|
104
104
|
def remove_defaults(hash)
|
105
105
|
hash.inject({}) do |memo, (k, v)|
|
106
|
-
if defaults[k] == v
|
106
|
+
if defaults[k.to_sym] == v
|
107
107
|
memo[k] = nil
|
108
108
|
else
|
109
109
|
memo[k] = v
|
data/lib/thor_addons/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thor-addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacopo Scrinzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- ".gitignore"
|
77
77
|
- ".travis.yml"
|
78
78
|
- CHANGELOG.md
|
79
|
+
- CONTRIBUTING.md
|
79
80
|
- Dockerfile
|
80
81
|
- Gemfile
|
81
82
|
- README.md
|