cog-rb 0.2.0 → 0.3.1
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 +11 -0
- data/bin/cogrb +0 -0
- data/lib/cog/bundle.rb +17 -19
- data/lib/cog/request.rb +1 -2
- data/lib/cog/version.rb +1 -1
- data/lib/cog.rb +0 -2
- data/lib/rspec/cog/setup.rb +10 -2
- data/lib/tasks/cog.rake +5 -5
- metadata +2 -4
- data/lib/cog/aggregate_command.rb +0 -57
- data/lib/cog/subcommand.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c809f7a4ef732bb4a4d9d04801385f1e5603bfa
|
4
|
+
data.tar.gz: cb5202722011ce28c55b76f86ee86d12858b3047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ebe57eeba800dc524e7126a7efd3d06d89d21a3de4e7cd06ba3275798f88833e5f0185ef9f56b454708dcdeebff4706a1746e7232f83f3c941bc03b151ea449
|
7
|
+
data.tar.gz: 5c8a2c5cb215b4afadb5bf5bb85366c089c363f599314c8fa8eca8716b7ac192dea219113148b86a4be0f880900cbbf88c82c3c9f1efb2d466d498841cf61139
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 0.3.1
|
2
|
+
|
3
|
+
* Adds `cogrb docker:release` task to build and push an updated Docker image in one step.
|
4
|
+
|
5
|
+
## 0.3.0 - Unreleased development version
|
6
|
+
|
7
|
+
**Note:** This version of `cog-rb` is not compatible with Cog versions lower than 0.14.
|
8
|
+
|
9
|
+
* Updates `cogrb templates:update` task to use bundle configuration version 4.
|
10
|
+
* Removes the subcommand support added in 0.2.0. We will revisit this in the future when subcommands are a first class feature in Cog. Attempting to support it at the command implementation level turned out to be unworkable.
|
11
|
+
|
1
12
|
## 0.2.0
|
2
13
|
|
3
14
|
* Adds support for subcommands
|
data/bin/cogrb
CHANGED
File without changes
|
data/lib/cog/bundle.rb
CHANGED
@@ -1,51 +1,49 @@
|
|
1
1
|
class Cog
|
2
2
|
class Bundle
|
3
|
-
attr_reader :name
|
3
|
+
attr_reader :name
|
4
4
|
|
5
|
-
def initialize(name, base_dir: nil
|
5
|
+
def initialize(name, base_dir: nil)
|
6
6
|
@name = name
|
7
7
|
@base_dir = base_dir || File.dirname($0)
|
8
|
-
@config = load_config(config_file || File.join(@base_dir, 'config.yaml'))
|
9
8
|
@module = create_bundle_module
|
10
|
-
|
11
|
-
load_commands
|
12
9
|
end
|
13
10
|
|
14
11
|
def create_bundle_module
|
15
12
|
return if Object.const_defined?('CogCmd')
|
16
|
-
|
17
13
|
Object.const_set('CogCmd', Module.new)
|
18
14
|
CogCmd.const_set(@name.capitalize, Module.new)
|
19
15
|
end
|
20
16
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
def command_instance(command_name)
|
18
|
+
command_path = command_name.split('-')
|
19
|
+
require File.join(@base_dir, 'lib', 'cog_cmd', @name, *command_path)
|
20
|
+
|
21
|
+
# translate snake-case command names to camel case
|
22
|
+
command_class = command_name.gsub(/(\A|_)([a-z])/) { $2.upcase }
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
# convert hyphenated command names into class hierarchies,
|
25
|
+
# e.g. template-list becomes Template::List.
|
26
|
+
command_class = command_class.split('-').map{ |seg| seg.capitalize }.join('::')
|
27
|
+
|
28
|
+
@module.const_get(command_class).new
|
30
29
|
end
|
31
30
|
|
32
31
|
def run_command
|
33
32
|
command = ENV['COG_COMMAND']
|
34
|
-
|
35
|
-
|
36
|
-
target = @module.const_get(command_class).new
|
33
|
+
target = command_instance(command)
|
37
34
|
target.execute
|
38
|
-
# Abort will end command execution and abort the pipeline
|
39
35
|
rescue Cog::Abort => msg
|
36
|
+
# Abort will end command execution and abort the pipeline
|
40
37
|
response = Cog::Response.new
|
41
38
|
response['body'] = msg
|
42
39
|
response.abort
|
43
40
|
response.send
|
44
|
-
# Stop will end command execution but the pipeline will continue
|
45
41
|
rescue Cog::Stop => msg
|
42
|
+
# Stop will end command execution but the pipeline will continue
|
46
43
|
response = Cog::Response.new
|
47
44
|
response['body'] = msg
|
48
45
|
response.send
|
49
46
|
end
|
47
|
+
|
50
48
|
end
|
51
49
|
end
|
data/lib/cog/request.rb
CHANGED
data/lib/cog/version.rb
CHANGED
data/lib/cog.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
require_relative 'cog/bundle'
|
3
3
|
require_relative 'cog/config'
|
4
4
|
require_relative 'cog/command'
|
5
|
-
require_relative 'cog/subcommand'
|
6
|
-
require_relative 'cog/aggregate_command'
|
7
5
|
require_relative 'cog/request'
|
8
6
|
require_relative 'cog/response'
|
9
7
|
require_relative 'cog/version'
|
data/lib/rspec/cog/setup.rb
CHANGED
@@ -39,7 +39,14 @@ module Cog::RSpec::Setup
|
|
39
39
|
let(:command_name){ raise "Must supply a :command_name!" }
|
40
40
|
|
41
41
|
let(:command) do
|
42
|
-
|
42
|
+
# translate snake-case command names to camel case
|
43
|
+
command_class = command_name.gsub(/(\A|_)([a-z])/) { $2.upcase }
|
44
|
+
|
45
|
+
# convert hyphenated command names into class hierarchies,
|
46
|
+
# e.g. template-list becomes Template::List.
|
47
|
+
command_class = command_class.split('-').map{ |seg| seg.capitalize }.join('::')
|
48
|
+
|
49
|
+
Object.const_get("CogCmd::#{bundle_name.capitalize}::#{command_class}").new
|
43
50
|
end
|
44
51
|
|
45
52
|
let(:invocation_id) { SecureRandom.uuid }
|
@@ -66,7 +73,8 @@ module Cog::RSpec::Setup
|
|
66
73
|
# TODO: receive a single input on STDIN, multiple for :fetch_input
|
67
74
|
|
68
75
|
# Expose previous inputs on STDIN
|
69
|
-
|
76
|
+
# We use allow because not all commands receive input
|
77
|
+
allow(STDIN).to receive(:read).and_return(cog_env.to_json)
|
70
78
|
|
71
79
|
# Use allow because not all commands will need to do this
|
72
80
|
allow(command).to receive(:fetch_input).and_return(cog_env)
|
data/lib/tasks/cog.rake
CHANGED
@@ -7,21 +7,21 @@ namespace :template do
|
|
7
7
|
task :update do
|
8
8
|
puts "Current bundle configuration version is #{config['version']}."
|
9
9
|
|
10
|
-
templates = FileList.new('templates
|
10
|
+
templates = FileList.new('templates/*')
|
11
11
|
return if templates.nil? || templates.size == 0
|
12
12
|
|
13
13
|
config['templates'] ||= {}
|
14
14
|
templates.each do |file|
|
15
15
|
(provider, template) = file.split('/')[-2..-1]
|
16
|
-
template.gsub!(
|
16
|
+
template.gsub!(/\..*\z/, '')
|
17
17
|
template_content = File.read(file)
|
18
18
|
|
19
19
|
config['templates'][template] ||= {}
|
20
|
-
prev_content = config['templates'][template][
|
20
|
+
prev_content = config['templates'][template]['body']
|
21
21
|
|
22
22
|
if template_content != prev_content
|
23
23
|
puts "Updating bundle configuration for template #{provider}/#{template}."
|
24
|
-
config['templates'][template][
|
24
|
+
config['templates'][template]['body'] = template_content
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -50,6 +50,6 @@ namespace :docker do
|
|
50
50
|
|
51
51
|
desc "Push updated Docker image"
|
52
52
|
task :push => [ :build ] do
|
53
|
-
|
53
|
+
system("docker", "push", docker_image)
|
54
54
|
end
|
55
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cog-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Imbriaco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -59,7 +59,6 @@ files:
|
|
59
59
|
- bin/setup
|
60
60
|
- cog-rb.gemspec
|
61
61
|
- lib/cog.rb
|
62
|
-
- lib/cog/aggregate_command.rb
|
63
62
|
- lib/cog/bundle.rb
|
64
63
|
- lib/cog/command.rb
|
65
64
|
- lib/cog/config.rb
|
@@ -69,7 +68,6 @@ files:
|
|
69
68
|
- lib/cog/service.rb
|
70
69
|
- lib/cog/services/memory.rb
|
71
70
|
- lib/cog/services/metadata.rb
|
72
|
-
- lib/cog/subcommand.rb
|
73
71
|
- lib/cog/version.rb
|
74
72
|
- lib/rspec/cog.rb
|
75
73
|
- lib/rspec/cog/matchers.rb
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'cog/exceptions'
|
2
|
-
|
3
|
-
class Cog
|
4
|
-
class AggregateCommand < Cog::Command
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
subcommands = self.class.const_get("SUBCOMMANDS")
|
8
|
-
subcommand = request.args.shift
|
9
|
-
|
10
|
-
require_subcommand!(subcommand, subcommands)
|
11
|
-
|
12
|
-
load_subcommands(subcommands)
|
13
|
-
|
14
|
-
@subcommand_class = create_subcommand_class(subcommand)
|
15
|
-
end
|
16
|
-
|
17
|
-
def run_command
|
18
|
-
response.content = subcommand().run_command
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def subcommand
|
24
|
-
@subcommand_inst ||= @subcommand_class.new(request)
|
25
|
-
end
|
26
|
-
|
27
|
-
def load_subcommands(subcommands)
|
28
|
-
subcommands.each do |sc|
|
29
|
-
require File.join(File.dirname($0), 'lib', 'cog_cmd', ENV['COG_BUNDLE'], ENV['COG_COMMAND'], sc)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_subcommand_class(subcommand)
|
34
|
-
subcommand_class = subcommand.gsub(/(\A|_)([a-z])/) { $2.upcase }
|
35
|
-
self.class.const_get(subcommand_class)
|
36
|
-
end
|
37
|
-
|
38
|
-
def require_subcommand!(subcommand, subcommands, exception = Cog::Abort)
|
39
|
-
unless subcommand
|
40
|
-
raise exception, missing_subcommand_msg(subcommands)
|
41
|
-
end
|
42
|
-
|
43
|
-
unless subcommands.include?(subcommand)
|
44
|
-
raise exception, unknown_subcommand_msg(subcommand, subcommands)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def missing_subcommand_msg(subcommands)
|
49
|
-
"Missing subcommand. Please specify one of '#{subcommands.join(', ')}'"
|
50
|
-
end
|
51
|
-
|
52
|
-
def unknown_subcommand_msg(subcommand, subcommands)
|
53
|
-
"Unknown subcommand '#{subcommand}'. Please specify one of '#{subcommands.join(', ')}'"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|