cogy 0.1.1 → 0.2.0
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 +27 -0
- data/LICENSE +1 -1
- data/README.md +166 -32
- data/app/controllers/cogy/cogy_controller.rb +10 -3
- data/lib/cogy/capistrano/cogy.rake +30 -0
- data/lib/cogy/capistrano.rb +15 -1
- data/lib/cogy/command.rb +5 -1
- data/lib/cogy/context.rb +37 -7
- data/lib/cogy/engine.rb +12 -0
- data/lib/cogy/version.rb +1 -1
- data/lib/cogy.rb +43 -40
- data/lib/generators/cogy/templates/cogy_config.rb +7 -4
- data/test/dummy/cogy/builtin_helpers.rb +11 -0
- data/test/dummy/cogy/foo.rb +3 -0
- data/test/dummy/cogy/json_response.rb +7 -0
- data/test/dummy/cogy/templates/pretty-command +5 -0
- data/test/dummy/config/initializers/cogy.rb +7 -4
- data/test/dummy/log/test.log +4846 -0
- data/test/integration/builtin_helpers_test.rb +24 -0
- data/test/integration/command_test.rb +5 -10
- data/test/integration/error_template_test.rb +20 -0
- data/test/integration/inventory_test.rb +18 -4
- data/test/integration/json_response_test.rb +29 -0
- metadata +16 -3
- data/lib/cogy/capistrano/v2/tasks.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18759faae517b4afcb5f2f133defd44078b37139
|
4
|
+
data.tar.gz: 23245b995cabda4b944844f5bbac83c4101ceafc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1934850a9fd090ca2f5917b1528b3e8f7b81274c80e5f05d71835af8f77a74993a45a2d9327f8b49ed737911fbfb38c0de4e5c791306bf49e6f6126cdbed6be7
|
7
|
+
data.tar.gz: 04fedae28608564a6983d5e869d98d38d5c1cabd7e1cb91c131d3ea4c0512c180d481374aaadf1abd3f66cd7bc0e562d210bd7bcc47e1f5a0584bb4e099c3fae
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## master (unreleased)
|
4
|
+
|
5
|
+
## 0.2.0 (2016-11-28)
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Add Capistrano 2 & 3 integration ([#13](https://github.com/skroutz/cogy/issues/13))
|
10
|
+
- Add support for defining Cog Templates ([#3](https://github.com/skroutz/cogy/issues/3))
|
11
|
+
- Add support for returning JSON to Cog ([#3](https://github.com/skroutz/cogy/issues/3))
|
12
|
+
- Arguments can also be accessed by their names ([#53](https://github.com/skroutz/cogy/issues/53))
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- Bundle-related configuration is now grouped together ([#41](https://github.com/skroutz/cogy/issues/41))
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
- Cog arguments are now ordered properly ([8a550](https://github.com/skroutz/cogy/commit/8a55004ef80822a816a7c0e3fdd6202d968f8926))
|
21
|
+
|
22
|
+
## 0.1.1 (2016-11-25)
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
|
26
|
+
- Everything in the Rails 4.2 series is now supported ([#47](https://github.com/skroutz/cogy/issues/47))
|
27
|
+
- Command options are now validated when initializing a command ([#48](https://github.com/skroutz/cogy/issues/48))
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -101,21 +101,32 @@ configuration initializer in your application.
|
|
101
101
|
Defining a new command:
|
102
102
|
|
103
103
|
```ruby
|
104
|
-
# in cogy/
|
104
|
+
# in cogy/my_commands.rb
|
105
105
|
|
106
106
|
on "foo", desc: "Echo a bar" do
|
107
107
|
"bar"
|
108
108
|
end
|
109
109
|
```
|
110
110
|
|
111
|
-
This will print "bar" back to the user who calls `!foo` in Slack
|
111
|
+
This will print "bar" back to the user who calls `!foo` in Slack.
|
112
|
+
|
113
|
+
Let's define a command that simply adds the numbers passed as arguments:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
# in cogy/calculations.rb
|
117
|
+
|
118
|
+
on "add", args: [:a, :b], desc: "Add two numbers" do
|
119
|
+
a.to_i + b.to_i
|
120
|
+
end
|
121
|
+
```
|
112
122
|
|
113
123
|
Inside the block there are the following pre-defined helpers available:
|
114
124
|
|
115
|
-
*
|
116
|
-
*
|
117
|
-
*
|
118
|
-
*
|
125
|
+
* `args`: an array containing the arguments passed to the command
|
126
|
+
* arguments can also be accessed by their names as local variables
|
127
|
+
* `opts`: a hash containing the options passed to the command
|
128
|
+
* `handle`: the chat handle of the user who called the command
|
129
|
+
* `env`: a hash containing the Cogy environment, that is, every environment variable
|
119
130
|
starting with 'COGY_' and set in the Relay
|
120
131
|
|
121
132
|
For instructions on defining your own helpers, see [Helpers](#helpers).
|
@@ -137,6 +148,76 @@ end
|
|
137
148
|
|
138
149
|
For more examples see the [test commands](https://github.com/skroutz/cogy/tree/master/test/dummy/cogy).
|
139
150
|
|
151
|
+
### Returning JSON to Cog
|
152
|
+
|
153
|
+
You can return JSON to Cog by just returning a `Hash`:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
on "foo", desc: "Just a JSON" do
|
157
|
+
{ a: 3 }
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
161
|
+
The hash automatically gets converted to JSON by Cogy. The above command would return the following response to Cog:
|
162
|
+
|
163
|
+
```
|
164
|
+
COG_TEMPLATE: foo
|
165
|
+
JSON
|
166
|
+
{"a":3}
|
167
|
+
```
|
168
|
+
|
169
|
+
To customize the Cog [template](#Templates) to be used, pass the `template` option:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
on "foo", desc: "Just a JSON", template: "bar" do
|
173
|
+
{ a: 3 }
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
Info on how Cog handles JSON can be found in the [official documentation](https://cog-book.operable.io/#_returning_data_from_cog).
|
178
|
+
|
179
|
+
### Templates
|
180
|
+
|
181
|
+
Templates are defined in their own files under `templates/` inside any of
|
182
|
+
the [command load paths](#Configuration). For example:
|
183
|
+
|
184
|
+
```
|
185
|
+
$ tree
|
186
|
+
.
|
187
|
+
├── README.rdoc
|
188
|
+
├── <..>
|
189
|
+
├── cogy
|
190
|
+
│ ├── some_commands.rb
|
191
|
+
│ └── templates
|
192
|
+
│ └── foo # <--- a template named 'foo'
|
193
|
+
|── <...>
|
194
|
+
```
|
195
|
+
|
196
|
+
Given the following template:
|
197
|
+
|
198
|
+
```
|
199
|
+
# in cogy/templates/foo
|
200
|
+
~ hello world ~
|
201
|
+
```
|
202
|
+
|
203
|
+
the resulting bundle config would look like this:
|
204
|
+
|
205
|
+
```yaml
|
206
|
+
---
|
207
|
+
cog_bundle_version: 4
|
208
|
+
name: foo
|
209
|
+
description: The bundle you really need
|
210
|
+
version: 0.0.1
|
211
|
+
commands:
|
212
|
+
<...>
|
213
|
+
templates:
|
214
|
+
foo:
|
215
|
+
body: |-
|
216
|
+
~ hello world ~
|
217
|
+
```
|
218
|
+
|
219
|
+
Refer to the [Cog book](https://cog-book.operable.io/#_templates) for more on
|
220
|
+
templates.
|
140
221
|
|
141
222
|
## Configuration
|
142
223
|
|
@@ -146,34 +227,42 @@ The configuration options provided are the following:
|
|
146
227
|
# in config/initializers/cogy.rb
|
147
228
|
|
148
229
|
Cogy.configure do |config|
|
149
|
-
#
|
150
|
-
#
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
230
|
+
# Configuration related to the generated Cog bundle. Will be used when
|
231
|
+
# generating the bundle config YAML to be installed.
|
232
|
+
config.bundle = {
|
233
|
+
# The bundle name.
|
234
|
+
#
|
235
|
+
# Default: "cogy"
|
236
|
+
name: "myapp",
|
237
|
+
|
238
|
+
# The bundle description
|
239
|
+
#
|
240
|
+
# Default: "Cog commands generated from Cogy"
|
241
|
+
description: "myapp-generated commands from Cogy",
|
242
|
+
|
243
|
+
# The bundle version.
|
244
|
+
#
|
245
|
+
# Can be either a string or an object that responds to `#call` and returns
|
246
|
+
# a string.
|
247
|
+
#
|
248
|
+
# Default: "0.0.1"
|
249
|
+
version: "0.0.1",
|
250
|
+
|
251
|
+
# if you used a callable object, it will be evaluated each time the inventory
|
252
|
+
# is called. This can be useful if you want the version to change
|
253
|
+
# automatically.
|
254
|
+
#
|
255
|
+
# For example, this will change the version only when a command is
|
256
|
+
# added or is modified (uses the 'grit' gem).
|
257
|
+
version: -> {
|
258
|
+
repo = Grit::Repo.new(Rails.root.to_s)
|
259
|
+
repo.log("HEAD", "cogy/", max_count: 1).first.date.strftime("%y%m%d.%H%M%S")
|
260
|
+
},
|
261
|
+
|
262
|
+
# The path in the Relay where the cogy command executable is located.
|
263
|
+
cogy_executable: "/cogcmd/cogy"
|
172
264
|
}
|
173
265
|
|
174
|
-
# The path in the Relay where the cogy command executable is located at.
|
175
|
-
config.executable_path = "/cogcmd/cogy"
|
176
|
-
|
177
266
|
# Paths in your application where the files that define the commands live in.
|
178
267
|
# For example the default value will search for all `*.rb` files in the `cogy/`
|
179
268
|
# directory relative to the root of your application.
|
@@ -248,6 +337,51 @@ is the following:
|
|
248
337
|
It can be overriden in the application by creating a view in
|
249
338
|
`app/views/cogy/error.text.erb`.
|
250
339
|
|
340
|
+
## Deployment
|
341
|
+
|
342
|
+
Cogy provides the `cogy:notify_cog` task for Capistrano. The following options
|
343
|
+
need to be set:
|
344
|
+
|
345
|
+
* `cogy_release_trigger_url`: This is the URL of the Cog Trigger that will
|
346
|
+
install the newly deployed bundle (ie. `!cogy:install`).
|
347
|
+
* `cogy_endpoint`: Where the Cogy Engine is mounted at.
|
348
|
+
For example `http://myapp.com/cogy`.
|
349
|
+
|
350
|
+
You can also configure the timeout value for the request to the Trigger by
|
351
|
+
setting the `cogy_trigger_timeout` option (default: 7).
|
352
|
+
|
353
|
+
The task can be found [here](https://github.com/skroutz/cogy/blob/master/lib/cogy/capistrano/cogy.rake).
|
354
|
+
|
355
|
+
### Capistrano 2
|
356
|
+
|
357
|
+
Add the following in `config/deploy.rb`:
|
358
|
+
|
359
|
+
```ruby
|
360
|
+
# in config/deploy.rb
|
361
|
+
require "cogy/capistrano"
|
362
|
+
|
363
|
+
set :cogy_release_trigger_url, "<TRIGGER-INVOCATION-URL>"
|
364
|
+
set :cogy_endpoint, "<COGY-MOUNT-POINT>"
|
365
|
+
```
|
366
|
+
|
367
|
+
The `cogy:notify_cog` task is automatically hooked after `deploy:restart`.
|
368
|
+
|
369
|
+
### Capistrano 3
|
370
|
+
|
371
|
+
Add the following in your Capfile:
|
372
|
+
|
373
|
+
```ruby
|
374
|
+
require "cogy/capistrano"
|
375
|
+
```
|
376
|
+
|
377
|
+
The `cogy:notify_cog` task should be manually hooked after the task that
|
378
|
+
restarts the application. For example:
|
379
|
+
|
380
|
+
```ruby
|
381
|
+
# in config/deploy.rb
|
382
|
+
after "deploy:restart_app", "cogy:notify_cog"
|
383
|
+
```
|
384
|
+
|
251
385
|
## Development
|
252
386
|
|
253
387
|
Running the tests and RuboCop:
|
@@ -12,7 +12,9 @@ module Cogy
|
|
12
12
|
# See https://github.com/skroutz/cogy-bundle.
|
13
13
|
def command
|
14
14
|
cmd = params[:cmd]
|
15
|
-
args = request.query_parameters.select { |k, _| k.start_with?("cog_argv_") }
|
15
|
+
args = request.query_parameters.select { |k, _| k.start_with?("cog_argv_") }
|
16
|
+
.sort_by { |k, _| k.match(/\d+\z/)[0] }.to_h.values
|
17
|
+
|
16
18
|
opts = request.query_parameters.select { |k, _| k.start_with?("cog_opt_") }
|
17
19
|
.transform_keys { |k| k.sub("cog_opt_", "") }
|
18
20
|
cogy_env = request.query_parameters.select { |k, _| k.start_with?("cogy_") }
|
@@ -20,8 +22,13 @@ module Cogy
|
|
20
22
|
|
21
23
|
begin
|
22
24
|
if (command = Cogy.commands[cmd])
|
23
|
-
|
24
|
-
|
25
|
+
result = Context.new(command, args, opts, user, cogy_env).invoke
|
26
|
+
if result.is_a?(Hash)
|
27
|
+
result = "COG_TEMPLATE: #{command.template || command.name}\n" \
|
28
|
+
"JSON\n" \
|
29
|
+
"#{result.to_json}"
|
30
|
+
end
|
31
|
+
render text: result
|
25
32
|
else
|
26
33
|
render status: 404, text: "The command '#{cmd}' does not exist."
|
27
34
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
namespace :cogy do
|
2
|
+
desc "Invoke the Cog Trigger that will install the Cogy-generated bundle"
|
3
|
+
task :notify_cog do
|
4
|
+
require "net/http"
|
5
|
+
require "timeout"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
trigger_url = fetch(:cogy_release_trigger_url)
|
9
|
+
cogy_endpoint = fetch(:cogy_endpoint)
|
10
|
+
|
11
|
+
begin
|
12
|
+
raise ":cogy_release_trigger_url must be set" if trigger_url.nil?
|
13
|
+
raise ":cogy_endpoint must be set" if cogy_endpoint.nil?
|
14
|
+
|
15
|
+
Timeout.timeout(fetch(:cogy_trigger_timeout) || 7) do
|
16
|
+
url = URI(trigger_url)
|
17
|
+
res = Net::HTTP.post_form(url, url: cogy_endpoint)
|
18
|
+
|
19
|
+
if !res.is_a?(Net::HTTPSuccess)
|
20
|
+
error = JSON.parse(res.body)["errors"]["error_message"]
|
21
|
+
if error !~ /version has already been taken/
|
22
|
+
puts "Error response (#{res.code}) from Cog trigger: #{error}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue => e
|
27
|
+
puts "Error invoking Cog trigger: #{e.class} #{e.message}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/cogy/capistrano.rb
CHANGED
@@ -1 +1,15 @@
|
|
1
|
-
require "
|
1
|
+
require "capistrano/version"
|
2
|
+
|
3
|
+
if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new("3.0.0")
|
4
|
+
load File.expand_path("../capistrano/cogy.rake", __FILE__)
|
5
|
+
else
|
6
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
7
|
+
_cset(:cogy_release_trigger_url) { nil }
|
8
|
+
_cset(:cogy_endpoint) { nil }
|
9
|
+
_cset(:cogy_trigger_timeout) { nil }
|
10
|
+
|
11
|
+
load File.expand_path("../capistrano/cogy.rake", __FILE__)
|
12
|
+
|
13
|
+
after "deploy:restart", "cogy:notify_cog"
|
14
|
+
end
|
15
|
+
end
|
data/lib/cogy/command.rb
CHANGED
@@ -17,8 +17,11 @@ module Cogy
|
|
17
17
|
# Attributes related to the bundle config in Cog
|
18
18
|
attr_reader :args, :opts, :desc, :long_desc, :examples, :rules
|
19
19
|
|
20
|
+
# The Cog template that the command should use
|
21
|
+
attr_reader :template
|
22
|
+
|
20
23
|
# See {Cogy.on}
|
21
|
-
def initialize(name, handler, args: [], opts: {}, desc:, long_desc: nil, examples: nil, rules: nil)
|
24
|
+
def initialize(name, handler, args: [], opts: {}, desc:, long_desc: nil, examples: nil, rules: nil, template: nil)
|
22
25
|
@name = name.to_s
|
23
26
|
@handler = handler
|
24
27
|
@args = [args].flatten.map!(&:to_s)
|
@@ -27,6 +30,7 @@ module Cogy
|
|
27
30
|
@long_desc = long_desc
|
28
31
|
@examples = examples
|
29
32
|
@rules = rules || ["allow"]
|
33
|
+
@template = template
|
30
34
|
|
31
35
|
validate_opts
|
32
36
|
end
|
data/lib/cogy/context.rb
CHANGED
@@ -8,6 +8,9 @@ module Cogy
|
|
8
8
|
# command (https://github.com/skroutz/cogy-bundle) on behalf of the user.
|
9
9
|
# You can think of it as the equivalent of the ActionPack's `Request` class.
|
10
10
|
class Context
|
11
|
+
# @return [Command] the {Command} to be invoked by {Context#invoke}
|
12
|
+
attr_reader :command
|
13
|
+
|
11
14
|
# @return [Array] The Cog command arguments as passed by the user who
|
12
15
|
# invoked the command.
|
13
16
|
#
|
@@ -31,22 +34,49 @@ module Cogy
|
|
31
34
|
# @see https://github.com/skroutz/cogy-bundle/blob/master/commands/cogy
|
32
35
|
attr_reader :env
|
33
36
|
|
34
|
-
def initialize(args, opts, handle, env)
|
37
|
+
def initialize(command, args, opts, handle, env)
|
38
|
+
@command = command
|
35
39
|
@args = args
|
36
40
|
@opts = opts
|
37
41
|
@handle = handle
|
38
42
|
@env = env
|
43
|
+
|
44
|
+
define_arg_helpers
|
39
45
|
end
|
40
46
|
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# @param [Command] cmd the {Command} to be executed
|
47
|
+
# Invokes the {Command}
|
44
48
|
#
|
45
|
-
# @return [
|
49
|
+
# @return [Object] the result of the command. This is what will get printed
|
46
50
|
# back to the user that invoked the command and is effectively the return
|
47
51
|
# value of the command body.
|
48
|
-
def
|
49
|
-
instance_eval(&
|
52
|
+
def invoke
|
53
|
+
instance_eval(&command.handler)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# Defines helpers for accessing the arguments of the respective {Command}
|
59
|
+
# by their name.
|
60
|
+
#
|
61
|
+
# For example, assuming a command:
|
62
|
+
#
|
63
|
+
# on "foo", args: [:a, :b] do
|
64
|
+
# a + b
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# If this was called with the arguments "foo" and "bar", it would return
|
68
|
+
# "foobar".
|
69
|
+
#
|
70
|
+
# @note Keep in mind that these helpers override the attribute readers
|
71
|
+
# of {Context}, so you're advised to avoid naming arguments with words
|
72
|
+
# like "args", "opts" etc.
|
73
|
+
#
|
74
|
+
# @todo We may want to implement a protection against overriding reserved
|
75
|
+
# words
|
76
|
+
def define_arg_helpers
|
77
|
+
command.args.each_with_index do |arg, i|
|
78
|
+
define_singleton_method(arg) { args[i] }
|
79
|
+
end
|
50
80
|
end
|
51
81
|
end
|
52
82
|
end
|
data/lib/cogy/engine.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
module Cogy
|
2
4
|
class Engine < ::Rails::Engine
|
3
5
|
isolate_namespace Cogy
|
4
6
|
|
5
7
|
config.after_initialize do
|
6
8
|
Cogy.command_load_paths.each do |path|
|
9
|
+
# Add commands
|
7
10
|
files = Dir[Rails.root.join(path, "*.rb")]
|
8
11
|
files.each { |f| Cogy.module_eval(File.read(f)) }
|
12
|
+
|
13
|
+
# Add templates
|
14
|
+
templates = Dir[Rails.root.join(path, "templates", "*")]
|
15
|
+
.select { |f| File.file?(f) }
|
16
|
+
|
17
|
+
templates.each do |t|
|
18
|
+
fname = Pathname(t).basename.to_s
|
19
|
+
Cogy.templates[fname] = { "body" => File.read(t).strip }
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
Context.include(Rails.application.routes.url_helpers)
|
data/lib/cogy/version.rb
CHANGED
data/lib/cogy.rb
CHANGED
@@ -12,35 +12,38 @@ module Cogy
|
|
12
12
|
@@commands = {}
|
13
13
|
mattr_accessor :commands
|
14
14
|
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
15
|
+
# Configuration related to the Cog bundle. Used in {Cogy.bundle_config}
|
16
|
+
# in order to generate the bundle config YAML.
|
17
|
+
#
|
18
|
+
# @see https://cog-book.operable.io/#_the_config_file
|
19
|
+
@@bundle = {
|
20
|
+
# The bundle name
|
21
|
+
name: "cogy",
|
22
|
+
|
23
|
+
# The bundle description
|
24
|
+
description: "Cog commands generated from Cogy",
|
25
|
+
|
26
|
+
# The bundle version.
|
27
|
+
#
|
28
|
+
# Can also be an object that responds to `#call` and returns a string. For
|
29
|
+
# example:
|
30
|
+
#
|
31
|
+
# -> { rand(1).to_s }
|
32
|
+
#
|
33
|
+
version: "0.0.1",
|
34
|
+
|
35
|
+
# The path in the Cog Relay where the cogy executable
|
36
|
+
# (ie. https://github.com/skroutz/cogy-bundle/blob/master/commands/cogy) is
|
37
|
+
# located.
|
38
|
+
cogy_executable: "/usr/bin/cogy"
|
39
|
+
}
|
40
|
+
mattr_accessor :bundle
|
41
|
+
|
42
|
+
# The Cog templates. Used in {Cogy.bundle_config}.
|
43
|
+
#
|
44
|
+
# @see https://cog-book.operable.io/#_templates
|
45
|
+
@@templates = {}
|
46
|
+
mattr_accessor :templates
|
44
47
|
|
45
48
|
# Paths where the files that define the commands will be searched in the
|
46
49
|
# host application.
|
@@ -101,16 +104,16 @@ module Cogy
|
|
101
104
|
#
|
102
105
|
# @return [Hash]
|
103
106
|
def self.bundle_config
|
104
|
-
version = if
|
105
|
-
|
107
|
+
version = if bundle[:version].respond_to?(:call)
|
108
|
+
bundle[:version].call
|
106
109
|
else
|
107
|
-
|
110
|
+
bundle[:version]
|
108
111
|
end
|
109
112
|
|
110
113
|
config = {
|
111
114
|
"cog_bundle_version" => COG_BUNDLE_VERSION,
|
112
|
-
"name" =>
|
113
|
-
"description" =>
|
115
|
+
"name" => bundle[:name],
|
116
|
+
"description" => bundle[:description],
|
114
117
|
"version" => version
|
115
118
|
}
|
116
119
|
|
@@ -118,7 +121,7 @@ module Cogy
|
|
118
121
|
|
119
122
|
commands.each do |name, cmd|
|
120
123
|
config["commands"][name] = {
|
121
|
-
"executable" =>
|
124
|
+
"executable" => bundle[:cogy_executable],
|
122
125
|
"description" => cmd.desc,
|
123
126
|
"rules" => cmd.rules
|
124
127
|
}
|
@@ -140,18 +143,18 @@ module Cogy
|
|
140
143
|
end
|
141
144
|
end
|
142
145
|
|
146
|
+
config["templates"] = templates if !templates.empty?
|
147
|
+
|
143
148
|
config
|
144
149
|
end
|
145
150
|
|
146
151
|
# Configures Cogy according to the passed block.
|
147
152
|
#
|
148
|
-
# @example
|
149
|
-
# Cogy.configure do |c|
|
150
|
-
# c.bundle_name = "foo"
|
151
|
-
# end
|
152
|
-
#
|
153
153
|
# @yield [self] yields {Cogy}
|
154
|
+
#
|
154
155
|
# @return [void]
|
156
|
+
#
|
157
|
+
# @see https://github.com/skroutz/cogy#configuration
|
155
158
|
def self.configure
|
156
159
|
yield self
|
157
160
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# See https://github.com/skroutz/cogy#configuration
|
2
2
|
Cogy.configure do |config|
|
3
|
-
#config.
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
3
|
+
#config.bundle = {
|
4
|
+
# name: "myapp",
|
5
|
+
# description: "Cog commands generated from myapp",
|
6
|
+
# version: "0.0.1",
|
7
|
+
# cogy_executable: "/usr/bin/cogy"
|
8
|
+
#}
|
9
|
+
#
|
7
10
|
#config.command_load_paths = ["cogy"]
|
8
11
|
end
|
data/test/dummy/cogy/foo.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
Cogy.configure do |c|
|
2
|
-
c.
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
c.bundle = {
|
3
|
+
name: "foo",
|
4
|
+
description: "The bundle you really need",
|
5
|
+
version: "0.0.1",
|
6
|
+
cogy_executable: "/usr/bin/foo"
|
7
|
+
}
|
8
|
+
|
6
9
|
c.command_load_paths = ["cogy"]
|
7
10
|
|
8
11
|
c.helper(:foo) { env["cogy_foo"] }
|