eac_tools 0.45.2 → 0.47.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +42 -36
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/lib/avm/data/callbacks.rb +37 -0
  5. data/sub/avm/lib/avm/data/package.rb +15 -7
  6. data/sub/avm/lib/avm/data/unit.rb +2 -23
  7. data/sub/avm/lib/avm/instances/base/auto_values/data.rb +1 -1
  8. data/sub/avm/lib/avm/instances/data/files_unit.rb +55 -0
  9. data/sub/avm/lib/avm/{data/instance → instances/data}/package.rb +2 -2
  10. data/sub/avm/lib/avm/instances/data/unit.rb +14 -0
  11. data/sub/avm/lib/avm/instances/data.rb +11 -0
  12. data/sub/avm/lib/avm/version.rb +1 -1
  13. data/sub/avm-eac_php_base0/avm-eac_php_base0.gemspec +3 -2
  14. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/instances/base.rb +14 -0
  15. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/instances.rb +11 -0
  16. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/source_generators/base.rb +28 -0
  17. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/source_generators.rb +11 -0
  18. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/sources/base.rb +17 -0
  19. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/sources.rb +11 -0
  20. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/version.rb +1 -1
  21. data/sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/source_generators/base_spec.rb +8 -0
  22. data/sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/source_generators/base_spec_files/no_options/index.php +0 -0
  23. data/sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/sources/base_spec.rb +7 -0
  24. data/sub/avm-eac_php_base0/template/avm/eac_php_base0/source_generators/base/index.php +0 -0
  25. data/sub/avm-eac_postgresql_base0/Gemfile +5 -0
  26. data/sub/avm-eac_postgresql_base0/avm-eac_postgresql_base0.gemspec +19 -0
  27. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/assert.rb +77 -0
  28. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/data_unit.rb +39 -0
  29. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance.rb +74 -0
  30. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance_with.rb +18 -0
  31. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/version.rb +7 -0
  32. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0.rb +9 -0
  33. data/sub/avm-eac_postgresql_base0/spec/rubocop_spec.rb +3 -0
  34. data/sub/avm-eac_postgresql_base0/spec/spec_helper.rb +4 -0
  35. data/sub/avm-eac_rails_base1/avm-eac_rails_base1.gemspec +4 -4
  36. data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/version.rb +1 -1
  37. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +2 -2
  38. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/files.rb +22 -0
  39. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/gitolite.rb +11 -0
  40. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/install.rb +37 -0
  41. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +3 -9
  42. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_package.rb +23 -0
  43. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/deploy.rb +1 -19
  44. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  45. data/sub/avm-eac_redmine_plugin_base0/avm-eac_redmine_plugin_base0.gemspec +2 -2
  46. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/init.rb +27 -0
  47. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/parent.rb +31 -0
  48. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/rubocop.rb +29 -0
  49. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/version.rb +31 -0
  50. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base.rb +2 -36
  51. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/init_file.rb +43 -0
  52. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/version.rb +1 -1
  53. data/sub/avm-eac_redmine_plugin_base0/spec/lib/avm/eac_redmine_plugin_base0/sources/init_file_spec.rb +14 -0
  54. data/sub/avm-eac_redmine_plugin_base0/spec/lib/avm/eac_redmine_plugin_base0/sources/init_file_spec_files/a_init_file.rb +12 -0
  55. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +3 -3
  56. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/base.rb +4 -4
  57. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  58. data/sub/avm-git/avm-git.gemspec +3 -3
  59. data/sub/avm-git/lib/avm/git/launcher/base/underlying.rb +1 -1
  60. data/sub/avm-git/lib/avm/git/version.rb +1 -1
  61. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/append_command_options.rb +38 -0
  62. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +17 -2
  63. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/debugging.rb +19 -0
  64. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +3 -0
  65. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/execution.rb +52 -0
  66. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +28 -84
  67. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/{command/exec_error.rb → execution_error.rb} +1 -3
  68. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb +45 -0
  69. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  70. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/command_spec.rb +93 -0
  71. metadata +61 -39
  72. data/sub/avm/lib/avm/data/instance/files_unit.rb +0 -41
  73. data/sub/avm/lib/avm/data/instance/unit.rb +0 -17
  74. data/sub/avm/lib/avm/data/instance.rb +0 -11
  75. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_unit.rb +0 -53
  76. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/execute_result.rb +0 -47
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacRedminePluginBase0
7
+ module Sources
8
+ class InitFile
9
+ common_constructor :path
10
+
11
+ VERSION_LINE_PATTERN = /\A(\s*)version\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze
12
+
13
+ def version
14
+ path.read.each_line.lazy.map { |line| line_value(line) }.find { |v| v }
15
+ end
16
+
17
+ def version=(new_value)
18
+ path.write(new_value_content(new_value))
19
+ end
20
+
21
+ private
22
+
23
+ # @return Version found in line, nil otherwise.
24
+ def line_value(line)
25
+ VERSION_LINE_PATTERN.if_match(line.rstrip, false) { |m| ::Gem::Version.new(m[2]) }
26
+ end
27
+
28
+ def new_value_content(new_value)
29
+ path.read.each_line
30
+ .map { |line| new_value_line(line, new_value) }
31
+ .join
32
+ end
33
+
34
+ def new_value_line(line, new_value)
35
+ m = VERSION_LINE_PATTERN.match(line)
36
+ return line unless m
37
+
38
+ "#{m[1]}version '#{new_value}'"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacRedminePluginBase0
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_redmine_plugin_base0/sources/init_file'
4
+
5
+ ::RSpec.describe ::Avm::EacRedminePluginBase0::Sources::InitFile do
6
+ let(:stubs_dir) { ::Pathname.new(__dir__).join('init_file_spec_files') }
7
+ let(:stub_file) { stubs_dir.join('a_init_file.rb') }
8
+ let(:instance) { described_class.new(stub_file) }
9
+ let(:target_version) { ::Gem::Version.new('0.16.0') }
10
+
11
+ describe '#version' do
12
+ it { expect(instance.version).to eq(target_version) }
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'redmine'
4
+
5
+ Redmine::Plugin.register :redmine_installer do
6
+ name 'Redmine Installer'
7
+ author 'Eduardo Henrique Bogoni'
8
+ description 'Installer for Redmine.'
9
+ url 'https://github.com/esquilo-azul/redmine_installer'
10
+ author_url 'https://github.com/eduardobogoni/'
11
+ version '0.16.0'
12
+ end
@@ -12,12 +12,12 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,template}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.54'
15
+ s.add_dependency 'avm', '~> 0.57'
16
16
  s.add_dependency 'avm-eac_generic_base0', '~> 0.8'
17
- s.add_dependency 'avm-eac_postgresql_base0', '~> 0.2'
17
+ s.add_dependency 'avm-eac_postgresql_base0', '~> 0.2', '>= 0.2.1'
18
18
  s.add_dependency 'avm-eac_ubuntu_base0', '~> 0.3'
19
19
  s.add_dependency 'avm-files', '~> 0.6'
20
- s.add_dependency 'eac_ruby_utils', '~> 0.106', '>= 0.106.1'
20
+ s.add_dependency 'eac_ruby_utils', '~> 0.107', '>= 0.107.1'
21
21
 
22
22
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.2'
23
23
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'avm/instances/base'
4
4
  require 'avm/eac_postgresql_base0/instance_with'
5
- require 'avm/data/instance/files_unit'
6
- require 'avm/data/instance/package'
5
+ require 'avm/instances/data/files_unit'
6
+ require 'avm/instances/data/package'
7
7
  require 'avm/eac_webapp_base0/instances/deploy/file_unit'
8
8
  require 'avm/eac_webapp_base0/instances/runners'
9
9
  require 'avm/eac_ubuntu_base0/instances/base'
@@ -34,7 +34,7 @@ module Avm
34
34
  end
35
35
 
36
36
  def data_package
37
- @data_package ||= ::Avm::Data::Instance::Package.new(
37
+ @data_package ||= ::Avm::Instances::Data::Package.new(
38
38
  self, units: { database: database_unit }.merge(files_units)
39
39
  )
40
40
  end
@@ -52,7 +52,7 @@ module Avm
52
52
 
53
53
  def files_units
54
54
  self.class.const_get('FILES_UNITS').transform_values do |fs_path_subpath|
55
- ::Avm::Data::Instance::FilesUnit.new(self, fs_path_subpath)
55
+ ::Avm::Instances::Data::FilesUnit.new(self, fs_path_subpath)
56
56
  end
57
57
  end
58
58
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacWebappBase0
5
- VERSION = '0.12.2'
5
+ VERSION = '0.12.3'
6
6
  end
7
7
  end
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.54'
15
+ s.add_dependency 'avm', '~> 0.57'
16
16
  s.add_dependency 'avm-files', '~> 0.6'
17
- s.add_dependency 'eac_git', '~> 0.13'
18
- s.add_dependency 'eac_ruby_utils', '~> 0.106', '>= 0.106.1'
17
+ s.add_dependency 'eac_git', '~> 0.14'
18
+ s.add_dependency 'eac_ruby_utils', '~> 0.108'
19
19
  s.add_dependency 'git', '~> 1.12'
20
20
 
21
21
  s.add_development_dependency 'aranha-parsers', '~> 0.8', '>= 0.8.5'
@@ -23,7 +23,7 @@ module Avm
23
23
  define_method exec_type do |*args|
24
24
  begin
25
25
  command(*args).send(exec_type)
26
- rescue ::EacRubyUtils::Envs::Command::ExecError
26
+ rescue ::EacRubyUtils::Envs::ExecutionError
27
27
  raise ::Avm::Git::Launcher::Error
28
28
  end
29
29
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Git
5
- VERSION = '0.10.0'
5
+ VERSION = '0.10.1'
6
6
  end
7
7
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'shellwords'
5
+
6
+ module EacRubyUtils
7
+ module Envs
8
+ class Command
9
+ class AppendCommandOptions
10
+ enable_method_class
11
+ common_constructor :command, :command_line, :options
12
+
13
+ def result
14
+ r = command_line
15
+ r = input.command + ' | ' + r if input
16
+ r = "cat #{Shellwords.escape(input_file)} | #{r}" if input_file
17
+ r += ' > ' + Shellwords.escape(output_file) if output_file
18
+ r
19
+ end
20
+
21
+ # @return [EacRubyUtils::Envs::Command, nil]
22
+ def input
23
+ options[:input]
24
+ end
25
+
26
+ # @return [Pathname, nil]
27
+ def input_file
28
+ options[:input_file].if_present(&:to_pathname)
29
+ end
30
+
31
+ # @return [Pathname, nil]
32
+ def output_file
33
+ options[:output_file].if_present(&:to_pathname)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -6,18 +6,33 @@ module EacRubyUtils
6
6
  module Envs
7
7
  class Command
8
8
  module Concat
9
+ AND_OPERATOR = '&&'
10
+ BEFORE_OPERATOR = ';'
11
+ OR_OPERATOR = '||'
12
+ PIPE_OPERATOR = '|'
13
+
9
14
  def concat(operator, other_command)
10
15
  duplicate_by_extra_options(concat: ::EacRubyUtils::Struct.new(
11
16
  operator: operator, command: other_command
12
17
  ))
13
18
  end
14
19
 
20
+ # @return [EacRubyUtils::Envs::Command]
21
+ def and(other_command)
22
+ concat(AND_OPERATOR, other_command)
23
+ end
24
+
25
+ # @return [EacRubyUtils::Envs::Command]
26
+ def before(other_command)
27
+ concat(BEFORE_OPERATOR, other_command)
28
+ end
29
+
15
30
  def or(other_command)
16
- concat('||', other_command)
31
+ concat(OR_OPERATOR, other_command)
17
32
  end
18
33
 
19
34
  def pipe(other_command)
20
- concat('|', other_command)
35
+ concat(PIPE_OPERATOR, other_command)
21
36
  end
22
37
 
23
38
  private
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Envs
5
+ class Command
6
+ module Debugging
7
+ def debug?
8
+ ENV['DEBUG'].to_s.strip != ''
9
+ end
10
+
11
+ # Print a message if debugging is enabled.
12
+ def debug_print(message)
13
+ message = message.to_s
14
+ puts message.if_respond(:light_red, message) if debug?
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'shellwords'
5
+
3
6
  module EacRubyUtils
4
7
  module Envs
5
8
  class Command
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/envs/execution_error'
4
+ require 'eac_ruby_utils/envs/execution_result'
5
+ require 'eac_ruby_utils/envs/process'
6
+ require 'eac_ruby_utils/envs/spawn'
7
+ require 'pp'
8
+
9
+ module EacRubyUtils
10
+ module Envs
11
+ class Command
12
+ module Execution
13
+ def execute!(options = {})
14
+ options[:exit_outputs] = status_results.merge(options[:exit_outputs].presence || {})
15
+ er = ::EacRubyUtils::Envs::ExecutionResult.new(execute(options), options)
16
+ return er.result if er.success?
17
+
18
+ raise ::EacRubyUtils::Envs::ExecutionError,
19
+ "execute! command failed: #{self}\n#{er.r.pretty_inspect}"
20
+ end
21
+
22
+ def execute(options = {})
23
+ c = command(options)
24
+ debug_print("BEFORE: #{c}")
25
+ t1 = Time.now
26
+ r = ::EacRubyUtils::Envs::Process.new(c).to_h
27
+ i = Time.now - t1
28
+ debug_print("AFTER [#{i}]: #{c}")
29
+ r
30
+ end
31
+
32
+ def spawn(options = {})
33
+ c = command(options)
34
+ debug_print("SPAWN: #{c}")
35
+ ::EacRubyUtils::Envs::Spawn.new(c)
36
+ end
37
+
38
+ def system!(options = {})
39
+ return if system(options)
40
+
41
+ raise ::EacRubyUtils::Envs::ExecutionError, "system! command failed: #{self}"
42
+ end
43
+
44
+ def system(options = {})
45
+ c = command(options)
46
+ debug_print(c)
47
+ Kernel.system(c)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,128 +1,72 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
- require 'eac_ruby_utils/envs/process'
5
- require 'eac_ruby_utils/envs/spawn'
6
- require 'pp'
7
4
  require 'shellwords'
8
5
 
9
6
  module EacRubyUtils
10
7
  module Envs
11
8
  class Command
12
- require_sub __FILE__, include_modules: true
13
-
14
- def initialize(env, command, extra_options = {})
15
- @env = env
16
- @extra_options = extra_options.with_indifferent_access
17
- if command.count == 1 && command.first.is_a?(Array)
18
- @command = command.first
19
- elsif command.is_a?(Array)
20
- @command = command
21
- else
22
- raise "Invalid argument command: #{command}|#{command.class}"
9
+ require_sub __FILE__, include_modules: true, require_dependency: true
10
+
11
+ class << self
12
+ # @param command [Array]
13
+ # @return [Array]
14
+ def sanitize_initialize_arguments(arguments)
15
+ if arguments.count == 1 && arguments.first.is_a?(Array)
16
+ arguments.first
17
+ elsif arguments.is_a?(Array)
18
+ arguments
19
+ else
20
+ raise "Invalid argument command: #{arguments}|#{arguments.class}"
21
+ end
23
22
  end
24
23
  end
25
24
 
26
- def args
27
- @command
25
+ common_constructor :env, :args, :extra_options, default: [{}] do
26
+ self.extra_options = extra_options.with_indifferent_access
27
+ self.args = self.class.sanitize_initialize_arguments(args)
28
28
  end
29
29
 
30
30
  def append(args)
31
- duplicate_by_command(@command + args)
31
+ duplicate_by_command(self.args + args)
32
32
  end
33
33
 
34
34
  def prepend(args)
35
- duplicate_by_command(args + @command)
35
+ duplicate_by_command(args + self.args)
36
36
  end
37
37
 
38
38
  def to_s
39
- "#{@command} [ENV: #{@env}]"
39
+ "#{args} [ENV: #{env}]"
40
40
  end
41
41
 
42
42
  def command(options = {})
43
- c = @command
44
- c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
45
43
  append_command_options(
46
- @env.command_line(
47
- append_chdir(append_concat(append_envvars(c)))
48
- ),
44
+ env.command_line(command_line_without_env),
49
45
  options
50
46
  )
51
47
  end
52
48
 
53
- def execute!(options = {})
54
- options[:exit_outputs] = status_results.merge(options[:exit_outputs].presence || {})
55
- er = ExecuteResult.new(execute(options), options)
56
- return er.result if er.success?
57
-
58
- raise ::EacRubyUtils::Envs::Command::ExecError,
59
- "execute! command failed: #{self}\n#{er.r.pretty_inspect}"
60
- end
61
-
62
- def execute(options = {})
63
- c = command(options)
64
- debug_print("BEFORE: #{c}")
65
- t1 = Time.now
66
- r = ::EacRubyUtils::Envs::Process.new(c).to_h
67
- i = Time.now - t1
68
- debug_print("AFTER [#{i}]: #{c}")
69
- r
70
- end
71
-
72
- def spawn(options = {})
73
- c = command(options)
74
- debug_print("SPAWN: #{c}")
75
- ::EacRubyUtils::Envs::Spawn.new(c)
76
- end
77
-
78
- def system!(options = {})
79
- return if system(options)
80
-
81
- raise ::EacRubyUtils::Envs::Command::ExecError, "system! command failed: #{self}"
82
- end
83
-
84
- def system(options = {})
85
- c = command(options)
86
- debug_print(c)
87
- Kernel.system(c)
49
+ # @return [String]
50
+ def command_line_without_env
51
+ c = args
52
+ c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
53
+ append_chdir(append_concat(append_envvars(c)))
88
54
  end
89
55
 
90
56
  protected
91
57
 
92
58
  def duplicate(command, extra_options)
93
- self.class.new(@env, command, extra_options)
59
+ self.class.new(env, command, extra_options)
94
60
  end
95
61
 
96
62
  private
97
63
 
98
- attr_reader :extra_options
99
-
100
64
  def duplicate_by_command(new_command)
101
- duplicate(new_command, @extra_options)
65
+ duplicate(new_command, extra_options)
102
66
  end
103
67
 
104
68
  def duplicate_by_extra_options(set_extra_options)
105
- duplicate(@command, @extra_options.merge(set_extra_options))
106
- end
107
-
108
- def debug?
109
- ENV['DEBUG'].to_s.strip != ''
110
- end
111
-
112
- # Print a message if debugging is enabled.
113
- def debug_print(message)
114
- message = message.to_s
115
- puts message.if_respond(:light_red, message) if debug?
116
- end
117
-
118
- def append_command_options(command, options)
119
- command = options[:input].command + ' | ' + command if options[:input]
120
- if options[:input_file]
121
- command = "cat #{Shellwords.escape(options[:input_file])}" \
122
- " | #{command}"
123
- end
124
- command += ' > ' + Shellwords.escape(options[:output_file]) if options[:output_file]
125
- command
69
+ duplicate(args, extra_options.merge(set_extra_options))
126
70
  end
127
71
 
128
72
  def escape(arg)
@@ -2,9 +2,7 @@
2
2
 
3
3
  module EacRubyUtils
4
4
  module Envs
5
- class Command
6
- class ExecError < ::RuntimeError
7
- end
5
+ class ExecutionError < ::RuntimeError
8
6
  end
9
7
  end
10
8
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/envs/execution_error'
4
+
5
+ module EacRubyUtils
6
+ module Envs
7
+ class ExecutionResult
8
+ attr_reader :r, :options
9
+
10
+ def initialize(result, options)
11
+ @r = result
12
+ @options = options
13
+ end
14
+
15
+ def result
16
+ return exit_code_zero_result if exit_code_zero?
17
+ return expected_error_result if expected_error?
18
+
19
+ raise ::EacRubyUtils::Envs::ExecutionError, 'Failed!'
20
+ end
21
+
22
+ def success?
23
+ exit_code_zero? || expected_error?
24
+ end
25
+
26
+ private
27
+
28
+ def exit_code_zero?
29
+ r[:exit_code]&.zero?
30
+ end
31
+
32
+ def exit_code_zero_result
33
+ r[options[:output] || :stdout]
34
+ end
35
+
36
+ def expected_error_result
37
+ options[:exit_outputs][r[:exit_code]]
38
+ end
39
+
40
+ def expected_error?
41
+ options[:exit_outputs].is_a?(Hash) && options[:exit_outputs].key?(r[:exit_code])
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.107.1'
4
+ VERSION = '0.108.0'
5
5
  end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/envs/command'
4
+ require 'eac_ruby_utils/envs/executable'
5
+ require 'eac_ruby_utils/envs/local_env'
6
+
7
+ RSpec.describe ::EacRubyUtils::Envs::Command do
8
+ let(:env) { ::EacRubyUtils::Envs::LocalEnv.new }
9
+ let(:echo) { env.executable('echo', '--version') }
10
+ let(:cat) { env.executable('cat', '--version') }
11
+ let(:not_existing_file) { ::Pathname.new('a_file_that_not_exists') }
12
+ let(:ok_command) { echo.command('-n', ok_command_output) }
13
+ let(:ok_command_output) { 'THE OUTPUT' }
14
+ let(:error_command) { cat.command(not_existing_file) }
15
+
16
+ it { expect(echo).to exist }
17
+ it { expect(cat).to exist }
18
+ it { expect(not_existing_file).not_to exist }
19
+
20
+ describe '#execute' do
21
+ it do
22
+ expect(ok_command.execute).to(
23
+ eq({ command: 'echo -n THE\\ OUTPUT', stdout: ok_command_output, stderr: '', exit_code: 0 })
24
+ )
25
+ end
26
+
27
+ it do
28
+ expect(error_command.execute).to(
29
+ eq({ command: 'cat a_file_that_not_exists', stdout: '',
30
+ stderr: "cat: a_file_that_not_exists: No such file or directory\n", exit_code: 256 })
31
+ )
32
+ end
33
+ end
34
+
35
+ describe '#execute!' do
36
+ it { expect(ok_command.execute!).to eq(ok_command_output) }
37
+
38
+ it do
39
+ expect { error_command.execute! }.to(
40
+ raise_error(::EacRubyUtils::Envs::ExecutionError)
41
+ )
42
+ end
43
+ end
44
+
45
+ describe '#system' do
46
+ it { expect(ok_command.system).to eq(true) }
47
+ it { expect(error_command.system).to eq(false) }
48
+ end
49
+
50
+ describe '#system!' do
51
+ it { expect { ok_command.system! }.not_to raise_error }
52
+
53
+ it do
54
+ expect { error_command.system! }.to(
55
+ raise_error(::EacRubyUtils::Envs::ExecutionError)
56
+ )
57
+ end
58
+ end
59
+
60
+ describe '#or' do
61
+ it do
62
+ expect(ok_command.or(error_command).execute).to(
63
+ eq({ command: 'echo -n THE\\ OUTPUT || cat a_file_that_not_exists',
64
+ stdout: ok_command_output, stderr: '', exit_code: 0 })
65
+ )
66
+ end
67
+
68
+ it do
69
+ expect(error_command.or(ok_command).execute).to(
70
+ eq({ command: 'cat a_file_that_not_exists || echo -n THE\\ OUTPUT',
71
+ stdout: ok_command_output,
72
+ stderr: "cat: a_file_that_not_exists: No such file or directory\n", exit_code: 0 })
73
+ )
74
+ end
75
+ end
76
+
77
+ describe '#pipe' do
78
+ it do
79
+ expect(ok_command.pipe(error_command).execute).to(
80
+ eq({ command: 'echo -n THE\\ OUTPUT | cat a_file_that_not_exists', stdout: '',
81
+ stderr: "cat: a_file_that_not_exists: No such file or directory\n", exit_code: 256 })
82
+ )
83
+ end
84
+
85
+ it do
86
+ expect(error_command.pipe(ok_command).execute).to(
87
+ eq({ command: 'cat a_file_that_not_exists | echo -n THE\\ OUTPUT',
88
+ stdout: ok_command_output,
89
+ stderr: "cat: a_file_that_not_exists: No such file or directory\n", exit_code: 0 })
90
+ )
91
+ end
92
+ end
93
+ end