thor-hollaback 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +96 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/thor/hollaback/version.rb +5 -0
- data/lib/thor/hollaback.rb +69 -0
- data/thor-hollaback.gemspec +31 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7c2d1acaaab65a5d804189d2fc4692fcb4195b0
|
4
|
+
data.tar.gz: ca820fec1e8ccb5b87302bc0662c222b8696b4a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d66df4c33e73cac3396129497f2992646a224e316e19fe1a417e1af0076fe5b7c60625f33693402653a0f25015a85311f3fb4b84126c1030c7356e059ef4c8dc
|
7
|
+
data.tar.gz: 4d515f4c686064c41577e497550d7b9951cc61ca8dab75c848b9b22aebe93911444a4cd61e1be85425cff57b74877c5ab9885630342c7f4272b3b35c229d186d
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Localytics http://www.localytics.com
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Thor::Hollaback
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/localytics/thor-hollaback.svg?branch=master)](https://travis-ci.org/localytics/thor-hollaback)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/localytics/thor-hollaback/badge.svg?branch=master)](https://coveralls.io/github/localytics/thor-hollaback?branch=master)
|
5
|
+
|
6
|
+
Adds callbacks to thor commands.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'thor-hollaback'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install thor-hollaback
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Uses the [`hollaback`](https://github.com/localytics/hollaback) gem to add callbacks to [`thor`](https://github.com/erikhuda/thor) commands. You can set CLI-level callbacks with the macros `before_all`, `after_all`, and `around_all`. You can set command-level callbacks with `before`, `after`, and `around`. Example below.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class CLI < Thor
|
30
|
+
before_all :say_hello
|
31
|
+
after_all :say_goodbye
|
32
|
+
|
33
|
+
desc 'first_test', 'First test command'
|
34
|
+
around :say
|
35
|
+
def first_test
|
36
|
+
puts 'How are you?'
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'second_test', 'Second test command'
|
40
|
+
def second_test
|
41
|
+
puts 'How are you?'
|
42
|
+
end
|
43
|
+
|
44
|
+
no_commands do
|
45
|
+
def say_hello
|
46
|
+
puts 'Hello!'
|
47
|
+
end
|
48
|
+
|
49
|
+
def say_goodbye
|
50
|
+
puts 'Goodbye!'
|
51
|
+
end
|
52
|
+
|
53
|
+
def say
|
54
|
+
puts 'Speaking...'
|
55
|
+
yield
|
56
|
+
puts '...done.'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
When invoked, the above CLI results with:
|
63
|
+
|
64
|
+
```
|
65
|
+
irb(main):001:0> CLI.start(['first_test'])
|
66
|
+
Hello!
|
67
|
+
Speaking...
|
68
|
+
How are you?
|
69
|
+
...done.
|
70
|
+
Goodbye!
|
71
|
+
=> nil
|
72
|
+
```
|
73
|
+
|
74
|
+
and
|
75
|
+
|
76
|
+
```
|
77
|
+
irb(main):001:0> CLI.start(['second_test'])
|
78
|
+
Hello!
|
79
|
+
How are you?
|
80
|
+
Goodbye!
|
81
|
+
=> nil
|
82
|
+
```
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
87
|
+
|
88
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/localytics/thor-hollaback.
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'hollaback'
|
3
|
+
require 'thor/hollaback/version'
|
4
|
+
|
5
|
+
class Thor
|
6
|
+
module Hollaback
|
7
|
+
module ClassExt
|
8
|
+
# Methods for overall callbacks
|
9
|
+
def class_callback_chain
|
10
|
+
@class_callback_chain ||= ::Hollaback::Chain.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def class_after(execute = nil, &block)
|
14
|
+
class_callback_chain.after(execute, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def class_before(execute = nil, &block)
|
18
|
+
class_callback_chain.before(execute, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def class_around(execute = nil, &block)
|
22
|
+
class_callback_chain.around(execute, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Methods for individual command callbacks
|
26
|
+
def callback_chain
|
27
|
+
@callback_chain ||= ::Hollaback::Chain.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def before(execute = nil, &block)
|
31
|
+
callback_chain.before(execute, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def after(execute = nil, &block)
|
35
|
+
callback_chain.after(execute, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def around(execute = nil, &block)
|
39
|
+
callback_chain.around(execute, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_command(meth)
|
43
|
+
super
|
44
|
+
commands[meth].callback_chain = callback_chain if commands[meth]
|
45
|
+
@callback_chain = nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module CommandExt
|
50
|
+
def self.prepended(base)
|
51
|
+
base.send(:attr_accessor, :callback_chain)
|
52
|
+
end
|
53
|
+
|
54
|
+
def run(cli, *args)
|
55
|
+
if !callback_chain ||
|
56
|
+
(callback_chain.empty? && cli.class.class_callback_chain.empty?)
|
57
|
+
|
58
|
+
super
|
59
|
+
else
|
60
|
+
combined = callback_chain + cli.class.class_callback_chain
|
61
|
+
combined.compile { super }.call(cli)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Thor.singleton_class.prepend(Thor::Hollaback::ClassExt)
|
69
|
+
Thor::Command.prepend(Thor::Hollaback::CommandExt)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'thor/hollaback/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'thor-hollaback'
|
8
|
+
spec.version = Thor::Hollaback::VERSION
|
9
|
+
spec.authors = ['Localytics']
|
10
|
+
spec.email = ['oss@localytics.com']
|
11
|
+
|
12
|
+
spec.summary = 'Adds callbacks to thor commands'
|
13
|
+
spec.homepage = 'https://github.com/localytics/thor-hollaback'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.files = files.reject { |f| f.match(%r{^test/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
23
|
+
spec.add_dependency 'hollaback', '~> 0.1.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.11'
|
29
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.39'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thor-hollaback
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Localytics
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hollaback
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.11'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.11'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.39'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.39'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- oss@localytics.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rubocop.yml"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/console
|
140
|
+
- bin/setup
|
141
|
+
- lib/thor/hollaback.rb
|
142
|
+
- lib/thor/hollaback/version.rb
|
143
|
+
- thor-hollaback.gemspec
|
144
|
+
homepage: https://github.com/localytics/thor-hollaback
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.5.1
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: Adds callbacks to thor commands
|
168
|
+
test_files: []
|