cobra_commander 0.8.1 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a07c92126bfb5a1179d1fb056a0c33452d5b9cab9087c9062d3c0e8203b3d165
4
- data.tar.gz: a338e59737c442e533d7c9cf951dde539666617d2c571999c8d104b1dddb68aa
3
+ metadata.gz: d77734cb3eeb9f21c539f66a92d15e8aa94030046db7cdad3be8f6ed191c00aa
4
+ data.tar.gz: feacbdfbafb7baf191948e81014d9335b1cddf4a1ddd0f0a2aeac13af823efb3
5
5
  SHA512:
6
- metadata.gz: b47bca554823ceaca8ce8449c0a0a955103d84dd979ebc232b577042ee3e2f6a5a99e976277cbe926a6f4e3929f072f69e086dfad6f9805f6c1bce6b5167ff01
7
- data.tar.gz: 27ee91733374ae24fbb24fe26fa3692bd0a2afa22ebbd5a213431b51f55a84631b5e0d9fcaa8f30c1ccc15095afe090b94bbe7ff6a955e4f19120e3b2e9f942a
6
+ metadata.gz: dd926a0cc0bf9978b9b3dae6319e5b33853a2191f0d3b82645e696355a671769bf23894de45a58fb02fe5d0bb302c986d2ec8b3d71559c414248a82e2822c921
7
+ data.tar.gz: 60c750c84313992647cf94463ecc31fda2e5e3502f21a6eaacf4d6dbf206eddb8cacbd28d8925547c2851034bb64e3775413467f0c00962397e42af7484ac986
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Version 0.9.0 - 2020-08-26
6
+
7
+ * Add support for parallel task execution to `cobra exec`.
8
+
5
9
  ## Version 0.8.1 - 2020-07-29
6
10
 
7
11
  * Fix CobraCommander::Executor when running [`bundler`](https://bundler.io/) based commands (i.e.: `bundle exec rspec`)
@@ -37,6 +37,8 @@ DESCRIPTION
37
37
  spec.add_dependency "bundler", "~> 1.17"
38
38
  spec.add_dependency "thor", ["< 2.0", ">= 0.18.1"]
39
39
  spec.add_dependency "ruby-graphviz", "~> 1.2.3"
40
+ spec.add_dependency "tty-command", "~> 0.9.0"
41
+ spec.add_dependency "tty-spinner", "~> 0.9.3"
40
42
 
41
43
  spec.add_development_dependency "bundler", "~> 1.17"
42
44
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "executor/component_exec"
4
+ require_relative "executor/multi_exec"
5
+
3
6
  module CobraCommander
4
7
  # Execute commands on all components of a ComponentTree
5
8
  module Executor
6
- def self.exec(components, command, printer = $stdout)
7
- Bundler.with_original_env do
8
- components.each do |component|
9
- component.root_paths.each do |path|
10
- printer.puts "===> #{component.name} (#{path})"
11
- output, = Open3.capture2e(command, chdir: path)
12
- printer.puts output
13
- end
14
- end
15
- end
9
+ def self.exec(components, command, output = $stdout, status_output = $stderr)
10
+ components = Array(components)
11
+ exec = if components.size == 1
12
+ ComponentExec.new(components.first)
13
+ else
14
+ MultiExec.new(components)
15
+ end
16
+ exec.run(command, output: output, spin_output: status_output)
16
17
  end
17
18
  end
18
19
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-command"
4
+
5
+ module CobraCommander
6
+ module Executor
7
+ # Execute a command on a single component
8
+ class ComponentExec
9
+ def initialize(component)
10
+ @component = component
11
+ end
12
+
13
+ def run(command, output: $stdout, **cmd_options)
14
+ tty = TTY::Command.new(pty: true, printer: :quiet, output: output)
15
+ Bundler.with_original_env do
16
+ @component.root_paths.all? do |path|
17
+ tty.run!(command, chdir: path, **cmd_options).success?
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-spinner"
4
+
5
+ require_relative "component_exec"
6
+
7
+ module CobraCommander
8
+ module Executor
9
+ # Executes a command on multiple components simultaniously
10
+ class MultiExec
11
+ def initialize(components)
12
+ @components = components
13
+ end
14
+
15
+ def run(command, output: $stdout, spin_output: $stderr, only_output_on_error: true, **cmd_options)
16
+ cmmd_output = StringIO.new
17
+ multi = TTY::Spinner::Multi.new("Running #{command}", output: spin_output)
18
+ @components.each do |component|
19
+ component_exec(multi, component, command, only_output_on_error: only_output_on_error,
20
+ stderr: :stdout, output: cmmd_output,
21
+ **cmd_options)
22
+ end
23
+ multi.auto_spin
24
+ output << cmmd_output.string
25
+ true
26
+ end
27
+
28
+ private
29
+
30
+ def component_exec(multi, component, command, **options)
31
+ exec = ComponentExec.new(component)
32
+ multi.register(*spinner(component.name)) do |spin|
33
+ exec.run(command, **options) ? spin.success : spin.error
34
+ end
35
+ end
36
+
37
+ def spinner(title)
38
+ pastel = Pastel.new
39
+ [":spinner #{title}", format: :bouncing,
40
+ success_mark: pastel.green("[DONE]"),
41
+ error_mark: pastel.red("[ERROR]")]
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CobraCommander
4
- VERSION = "0.8.1"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cobra_commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Langfeld
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-07-29 00:00:00.000000000 Z
13
+ date: 2020-08-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -60,6 +60,34 @@ dependencies:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: 1.2.3
63
+ - !ruby/object:Gem::Dependency
64
+ name: tty-command
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.9.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.0
77
+ - !ruby/object:Gem::Dependency
78
+ name: tty-spinner
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.9.3
84
+ type: :runtime
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.9.3
63
91
  - !ruby/object:Gem::Dependency
64
92
  name: bundler
65
93
  requirement: !ruby/object:Gem::Requirement
@@ -200,6 +228,8 @@ files:
200
228
  - lib/cobra_commander/dependencies/yarn/package_repo.rb
201
229
  - lib/cobra_commander/dependencies/yarn_workspace.rb
202
230
  - lib/cobra_commander/executor.rb
231
+ - lib/cobra_commander/executor/component_exec.rb
232
+ - lib/cobra_commander/executor/multi_exec.rb
203
233
  - lib/cobra_commander/output.rb
204
234
  - lib/cobra_commander/output/ascii_tree.rb
205
235
  - lib/cobra_commander/output/flat_list.rb