carrasco 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbf7a3497241483dd63b3040a8e31a26f4a808a7
4
- data.tar.gz: 2b648b49eb838a6eb907fee38160dc1ff155115b
3
+ metadata.gz: e45dc01e5164f48798e8d8c62de5d1a6e78cda99
4
+ data.tar.gz: 6e793644e8aa7101f3a9de015a6db485b9c0f8ad
5
5
  SHA512:
6
- metadata.gz: 022fdb6cdbaf7356029be6eb064b973be7971214cd7c7a4ba8e635051338e80784cc7a82d214208c21e4162e9afa006d56878aa40712d2d90b5e9c3e7b8f3980
7
- data.tar.gz: c9dff8824189cc55ded4b491e2658151efe6c447d981e935391eb0550b900cec9c27e46b3d7db91985b6ffce94c7c8ed58dea0e3db7a779296564fbe623ed8ad
6
+ metadata.gz: ac793a0777af3ee7acbf7e8b061dd124c460a977235ce3b9968adba6724932f96a70eed2081dc1555b601a3487819a1161929dcd4b68a969825c89ff793ff74b
7
+ data.tar.gz: 7c2c22877c0039e65de47adb9170dcdf26f31ee6f579951f82b512cd46f0bb60cf4e235dbfd14cffd13c7e3c5d3a0d8bd23ddbb40dca686979027062c66f4aa2
data/.carrasco.yml CHANGED
@@ -12,14 +12,27 @@ commands:
12
12
 
13
13
  ls:
14
14
  description: List /tmp folder
15
- command: ls /tmp
15
+ command: ls /tmp | head
16
+
17
+ ls_current:
18
+ description: List current dir
19
+ command: ls .
16
20
 
17
21
  ls_with_error:
18
22
  description: list folder that does not exist
19
23
  command: ls /tmp/file_that_does_not_exist
20
24
 
21
- # to be implemented
22
25
  groups:
23
- qa:
24
- - test
25
- - phpunit
26
+ list_all:
27
+ description: list directories
28
+ break_on_failure: true
29
+ commands:
30
+ - ls
31
+ - ls_current
32
+
33
+ list_some:
34
+ description: list directories
35
+ break_on_failure: false
36
+ commands:
37
+ - ls
38
+ - ls_current
data/.travis.yml CHANGED
@@ -9,3 +9,5 @@ rvm:
9
9
  - 2.2
10
10
 
11
11
  sudo: false
12
+
13
+ script: ./exe/carrasco test
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Heartless and easy script execution
4
4
 
5
5
  [![Build Status](https://travis-ci.org/mjacobus/carrasco.svg)](https://travis-ci.org/mjacobus/carrasco)
6
- [![Code Coverage](https://scrutinizer-ci.com/g/mjacobus/carrasco/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mjacobus/carrasco/?branch=master)
6
+ [![Coverage Status](https://coveralls.io/repos/mjacobus/carrasco/badge.svg?branch=master&service=github)](https://coveralls.io/github/mjacobus/carrasco?branch=master)
7
7
  [![Code Climate](https://codeclimate.com/github/mjacobus/carrasco/badges/gpa.svg)](https://codeclimate.com/github/mjacobus/carrasco)
8
8
  [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mjacobus/carrasco/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mjacobus/carrasco/?branch=master)
9
9
  [![Dependency Status](https://gemnasium.com/mjacobus/carrasco.svg)](https://gemnasium.com/mjacobus/carrasco)
@@ -49,8 +49,13 @@ commands:
49
49
  # to be implemented
50
50
  groups:
51
51
  qa:
52
- - test
53
- - phpunit
52
+ description: Runs qa tools
53
+ # if you want phpunit to run even if the test task fails
54
+ # defaults to true
55
+ break_on_failure: false
56
+ commands:
57
+ - test
58
+ - phpunit
54
59
  ```
55
60
 
56
61
  You can execute:
@@ -12,5 +12,15 @@ module Carrasco
12
12
  @help = options[:help] || command_name
13
13
  @description = options[:description] || "description not given"
14
14
  end
15
+
16
+ def inject_into_class(klass)
17
+ command = self
18
+ klass.desc(help, description)
19
+ klass.class_eval do
20
+ define_method(command.command_name) do
21
+ execute_command(command)
22
+ end
23
+ end
24
+ end
15
25
  end
16
26
  end
@@ -1,22 +1,29 @@
1
+ require "thor/core_ext/hash_with_indifferent_access"
2
+
1
3
  module Carrasco
2
4
  class CommandBuilder
3
5
  def from_config(config)
6
+ config = Thor::CoreExt::HashWithIndifferentAccess.new(config)
4
7
  klass = Class.new(Thor)
5
8
 
6
- config['commands'].each do |method, options|
7
- command = Command.new(method, options)
8
- inject_command_into_class(command, klass)
9
- end
9
+ build_commands(config[:commands] || [], klass)
10
+ build_grups(config[:groups] || [], klass)
10
11
 
11
12
  klass
12
13
  end
13
14
 
14
- def inject_command_into_class(command, klass)
15
- klass.desc(command.help, command.description)
16
- klass.class_eval do
17
- define_method(command.command_name) do
18
- execute_command(command)
19
- end
15
+ private
16
+
17
+ def build_commands(commands, klass)
18
+ commands.each do |method, options|
19
+ command = Command.new(method, options)
20
+ command.inject_into_class(klass)
21
+ end
22
+ end
23
+
24
+ def build_grups(groups, klass)
25
+ groups.each do |group_name, options|
26
+ Group.new(group_name, options).inject_into_class(klass)
20
27
  end
21
28
  end
22
29
  end
@@ -0,0 +1,31 @@
1
+ require "thor/core_ext/hash_with_indifferent_access"
2
+
3
+ module Carrasco
4
+ class Group
5
+ InvalidGroupError = Class.new(StandardError)
6
+
7
+ attr_reader :command_name, :commands, :description, :help, :break_on_failure
8
+
9
+ def initialize(group_name, options = {})
10
+ options = Thor::CoreExt::HashWithIndifferentAccess.new(options)
11
+ @command_name = group_name
12
+ @help = options[:help] || command_name
13
+ @description = options[:description] || "description not given"
14
+ @break_on_failure = options[:break_on_failure]
15
+ @break_on_failure = true if break_on_failure.nil?
16
+ @commands = options.fetch('commands') do
17
+ raise InvalidGroupError, "Commands not provided for group '#{group_name}'"
18
+ end
19
+ end
20
+
21
+ def inject_into_class(klass)
22
+ group = self
23
+ klass.desc(help, description)
24
+ klass.class_eval do
25
+ define_method(group.command_name) do
26
+ execute_commands(group.commands, group.break_on_failure)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/carrasco/thor.rb CHANGED
@@ -2,6 +2,8 @@ require "thor"
2
2
 
3
3
  module Carrasco
4
4
  class Thor < ::Thor
5
+ CommandFailed = Class.new(StandardError)
6
+
5
7
  no_commands do
6
8
  def execute_command(command)
7
9
  command_executer.execute!(command)
@@ -14,6 +16,35 @@ module Carrasco
14
16
  def command_executer
15
17
  @@command_executer ||= CommandExecuter.new
16
18
  end
19
+
20
+ def execute_commands(commands, break_on_failure)
21
+ if break_on_failure
22
+ return execute_with_break_on_failure(commands)
23
+ end
24
+
25
+ errors = []
26
+
27
+ commands.each do |command|
28
+ begin
29
+ send(command)
30
+ rescue StandardError => e
31
+ errors << e.message
32
+ end
33
+ end
34
+
35
+ unless errors.empty?
36
+ messages = errors.map {|e| "'#{e}'"}
37
+ raise CommandFailed, "Failed with messages: #{messages.join(', ')}"
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def execute_with_break_on_failure(commands)
44
+ commands.each do |command|
45
+ send(command)
46
+ end
47
+ end
17
48
  end
18
49
  end
19
50
  end
@@ -1,3 +1,3 @@
1
1
  module Carrasco
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/carrasco.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "carrasco/version"
2
2
  require "carrasco/command"
3
+ require "carrasco/group"
3
4
  require "carrasco/thor"
4
5
  require "carrasco/command_builder"
5
6
  require "carrasco/command_executer"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrasco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Jacobus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-03 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -161,6 +161,7 @@ files:
161
161
  - lib/carrasco/command.rb
162
162
  - lib/carrasco/command_builder.rb
163
163
  - lib/carrasco/command_executer.rb
164
+ - lib/carrasco/group.rb
164
165
  - lib/carrasco/thor.rb
165
166
  - lib/carrasco/version.rb
166
167
  homepage: https://github.com/mjacobus/carrasco
@@ -184,9 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  requirements: []
186
187
  rubyforge_project:
187
- rubygems_version: 2.4.6
188
+ rubygems_version: 2.4.8
188
189
  signing_key:
189
190
  specification_version: 4
190
191
  summary: Command executor
191
192
  test_files: []
192
- has_rdoc: