eac_tools 0.46.0 → 0.47.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +14 -13
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm-eac_php_base0/avm-eac_php_base0.gemspec +3 -2
  5. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/instances/base.rb +14 -0
  6. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/instances.rb +11 -0
  7. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/source_generators/base.rb +28 -0
  8. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/source_generators.rb +11 -0
  9. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/sources/base.rb +17 -0
  10. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/sources.rb +11 -0
  11. data/sub/avm-eac_php_base0/lib/avm/eac_php_base0/version.rb +1 -1
  12. data/sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/source_generators/base_spec.rb +8 -0
  13. data/sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/source_generators/base_spec_files/no_options/index.php +0 -0
  14. data/sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/sources/base_spec.rb +7 -0
  15. data/sub/avm-eac_php_base0/template/avm/eac_php_base0/source_generators/base/index.php +0 -0
  16. data/sub/avm-git/avm-git.gemspec +3 -3
  17. data/sub/avm-git/lib/avm/git/launcher/base/underlying.rb +1 -1
  18. data/sub/avm-git/lib/avm/git/version.rb +1 -1
  19. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/append_command_options.rb +38 -0
  20. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +17 -2
  21. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/debugging.rb +19 -0
  22. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +3 -0
  23. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/execution.rb +52 -0
  24. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +28 -84
  25. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/{command/exec_error.rb → execution_error.rb} +1 -3
  26. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb +45 -0
  27. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  28. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/command_spec.rb +93 -0
  29. metadata +24 -16
  30. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/execute_result.rb +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42d2af3ec5802d3d4deaef86b0e225332d92bb079767121a8601d0d7a9765418
4
- data.tar.gz: 062b466f4a749f6094769ede0583d1bd574f73ae05ffa30e0aeaa8a167e6ea2b
3
+ metadata.gz: 3418d6903a368e33472395b53a332d45ba663fef893c5e657f68ccb5bfc22c17
4
+ data.tar.gz: 53b2d9b4c6a88ae9371176752c14bcaa623537f685f9400080c61ec274cee36e
5
5
  SHA512:
6
- metadata.gz: ae897ed254a4902dd543c1644015ee6f4ed269bd401949594cd8c5bfc764d9abce299cdbe4a9c6a04de72ec8f0870c93e617d36b39e7c83b202058970dd5f94b
7
- data.tar.gz: 349afc035604be730dec4bc4a1ebf9ef670dc15c27364f2abe4a752d853c8a2f4a689493f087f86598434d886900d0d81cb26409970dba895f8e7028c92d7869
6
+ metadata.gz: 37e4b8af6160ac8056ad0c724639b304260ce2c4b47fb405488a8fa529d01d3535264b0b28a06bff17f4adfd62eb47253f4d81c20e52e77637100ff05937aa05
7
+ data.tar.gz: 1c72ca7d308189e28abc9bd8b1f01ff7d02a74841bffe80374f43fd9da5be792c6c90fce48ceef451bff95f56117fe95f5dde5d3869393696d2d8ae4dece2edf
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eac_tools (0.46.0)
5
- avm (~> 0.57)
4
+ eac_tools (0.47.0)
5
+ avm (~> 0.58)
6
6
  avm-eac_asciidoctor_base0 (~> 0.12)
7
7
  avm-eac_generic_base0 (~> 0.8)
8
8
  avm-eac_latex_base0 (~> 0.3)
9
- avm-eac_php_base0 (~> 0.3)
9
+ avm-eac_php_base0 (~> 0.4)
10
10
  avm-eac_rails_base0 (~> 0.8, >= 0.8.1)
11
11
  avm-eac_rails_base1 (~> 0.7, >= 0.7.1)
12
12
  avm-eac_redmine_base0 (~> 0.17)
@@ -15,7 +15,7 @@ PATH
15
15
  avm-eac_webapp_base0 (~> 0.12, >= 0.12.3)
16
16
  avm-eac_wordpress_base0 (~> 0.2, >= 0.2.1)
17
17
  avm-tools (~> 0.142, >= 0.142.6)
18
- eac_ruby_utils (~> 0.107, >= 0.107.1)
18
+ eac_ruby_utils (~> 0.108)
19
19
 
20
20
  PATH
21
21
  remote: sub/aranha-parsers
@@ -58,9 +58,10 @@ PATH
58
58
  PATH
59
59
  remote: sub/avm-eac_php_base0
60
60
  specs:
61
- avm-eac_php_base0 (0.3.0)
62
- avm-eac_generic_base0 (~> 0.7)
63
- eac_ruby_utils (~> 0.106)
61
+ avm-eac_php_base0 (0.4.0)
62
+ avm-eac_generic_base0 (~> 0.8)
63
+ avm-eac_webapp_base0 (~> 0.12, >= 0.12.3)
64
+ eac_ruby_utils (~> 0.108)
64
65
 
65
66
  PATH
66
67
  remote: sub/avm-eac_postgresql_base0
@@ -152,11 +153,11 @@ PATH
152
153
  PATH
153
154
  remote: sub/avm-git
154
155
  specs:
155
- avm-git (0.10.0)
156
- avm (~> 0.54)
156
+ avm-git (0.10.1)
157
+ avm (~> 0.57)
157
158
  avm-files (~> 0.6)
158
- eac_git (~> 0.13)
159
- eac_ruby_utils (~> 0.106, >= 0.106.1)
159
+ eac_git (~> 0.14)
160
+ eac_ruby_utils (~> 0.108)
160
161
  git (~> 1.12)
161
162
 
162
163
  PATH
@@ -242,7 +243,7 @@ PATH
242
243
  PATH
243
244
  remote: sub/eac_ruby_utils
244
245
  specs:
245
- eac_ruby_utils (0.107.1)
246
+ eac_ruby_utils (0.108.0)
246
247
  activesupport (>= 4, < 7)
247
248
  addressable (~> 2.8, >= 2.8.1)
248
249
  bundler
@@ -337,7 +338,7 @@ GEM
337
338
  parslet (2.0.0)
338
339
  public_suffix (5.0.0)
339
340
  racc (1.6.0)
340
- rack (3.0.0)
341
+ rack (3.0.1)
341
342
  rainbow (3.1.1)
342
343
  rchardet (1.8.0)
343
344
  rexml (3.2.5)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTools
4
- VERSION = '0.46.0'
4
+ VERSION = '0.47.0'
5
5
  end
@@ -12,8 +12,9 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,locale,template}/**/*']
14
14
 
15
- s.add_dependency 'avm-eac_generic_base0', '~> 0.7'
16
- s.add_dependency 'eac_ruby_utils', '~> 0.106'
15
+ s.add_dependency 'avm-eac_generic_base0', '~> 0.8'
16
+ s.add_dependency 'avm-eac_webapp_base0', '~> 0.12', '>= 0.12.3'
17
+ s.add_dependency 'eac_ruby_utils', '~> 0.108'
17
18
 
18
19
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5', '>= 0.5.1'
19
20
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module EacPhpBase0
8
+ module Instances
9
+ class Base < ::Avm::EacWebappBase0::Instances::Base
10
+ FILES_UNITS = {}.freeze
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacPhpBase0
7
+ module Instances
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/source_generators/base'
4
+ require 'eac_templates/core_ext'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module EacPhpBase0
9
+ module SourceGenerators
10
+ class Base < ::Avm::SourceGenerators::Base
11
+ OPTIONS = {}.freeze
12
+
13
+ enable_speaker
14
+ enable_simple_cache
15
+
16
+ class << self
17
+ def option_list
18
+ OPTIONS.inject(super) { |a, e| a.option(*e) }
19
+ end
20
+ end
21
+
22
+ def perform
23
+ template.apply(self, target_path)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacPhpBase0
7
+ module SourceGenerators
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_webapp_base0/sources/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module EacPhpBase0
8
+ module Sources
9
+ class Base < ::Avm::EacWebappBase0::Sources::Base
10
+ # @return [Boolean]
11
+ def valid?
12
+ path.glob('*.php').any?(&:file?)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacPhpBase0
7
+ module Sources
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacPhpBase0
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_php_base0/source_generators/base'
4
+ require 'avm/source_generators/runner'
5
+
6
+ RSpec.describe ::Avm::EacPhpBase0::SourceGenerators::Base do
7
+ include_examples 'avm_source_generated', __FILE__, 'EacPhpBase0'
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_php_base0/sources/base'
4
+
5
+ ::RSpec.describe ::Avm::EacPhpBase0::Sources::Base do
6
+ include_examples 'in_avm_registry', 'sources'
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.46.0
4
+ version: 0.47.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-16 00:00:00.000000000 Z
11
+ date: 2022-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.57'
19
+ version: '0.58'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.57'
26
+ version: '0.58'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: avm-eac_asciidoctor_base0
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.3'
75
+ version: '0.4'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.3'
82
+ version: '0.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: avm-eac_rails_base0
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -234,20 +234,14 @@ dependencies:
234
234
  requirements:
235
235
  - - "~>"
236
236
  - !ruby/object:Gem::Version
237
- version: '0.107'
238
- - - ">="
239
- - !ruby/object:Gem::Version
240
- version: 0.107.1
237
+ version: '0.108'
241
238
  type: :runtime
242
239
  prerelease: false
243
240
  version_requirements: !ruby/object:Gem::Requirement
244
241
  requirements:
245
242
  - - "~>"
246
243
  - !ruby/object:Gem::Version
247
- version: '0.107'
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: 0.107.1
244
+ version: '0.108'
251
245
  - !ruby/object:Gem::Dependency
252
246
  name: eac_ruby_gem_support
253
247
  requirement: !ruby/object:Gem::Requirement
@@ -420,6 +414,12 @@ files:
420
414
  - sub/avm-eac_php_base0/lib/avm/eac_php_base0/executables.rb
421
415
  - sub/avm-eac_php_base0/lib/avm/eac_php_base0/file_formats.rb
422
416
  - sub/avm-eac_php_base0/lib/avm/eac_php_base0/file_formats/base.rb
417
+ - sub/avm-eac_php_base0/lib/avm/eac_php_base0/instances.rb
418
+ - sub/avm-eac_php_base0/lib/avm/eac_php_base0/instances/base.rb
419
+ - sub/avm-eac_php_base0/lib/avm/eac_php_base0/source_generators.rb
420
+ - sub/avm-eac_php_base0/lib/avm/eac_php_base0/source_generators/base.rb
421
+ - sub/avm-eac_php_base0/lib/avm/eac_php_base0/sources.rb
422
+ - sub/avm-eac_php_base0/lib/avm/eac_php_base0/sources/base.rb
423
423
  - sub/avm-eac_php_base0/lib/avm/eac_php_base0/version.rb
424
424
  - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/file_formats/base_spec.rb
425
425
  - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/file_formats/base_spec_files/php_code.php.source
@@ -430,8 +430,12 @@ files:
430
430
  - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/file_formats/base_spec_files/php_html_code.php.target
431
431
  - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/file_formats/base_spec_files/php_iso88591_code.php.source
432
432
  - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/file_formats/base_spec_files/php_iso88591_code.php.target
433
+ - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/source_generators/base_spec.rb
434
+ - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/source_generators/base_spec_files/no_options/index.php
435
+ - sub/avm-eac_php_base0/spec/lib/avm/eac_php_base0/sources/base_spec.rb
433
436
  - sub/avm-eac_php_base0/spec/rubocop_spec.rb
434
437
  - sub/avm-eac_php_base0/spec/spec_helper.rb
438
+ - sub/avm-eac_php_base0/template/avm/eac_php_base0/source_generators/base/index.php
435
439
  - sub/avm-eac_postgresql_base0/Gemfile
436
440
  - sub/avm-eac_postgresql_base0/avm-eac_postgresql_base0.gemspec
437
441
  - sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0.rb
@@ -1592,12 +1596,15 @@ files:
1592
1596
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs.rb
1593
1597
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb
1594
1598
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb
1599
+ - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/append_command_options.rb
1595
1600
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb
1601
+ - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/debugging.rb
1596
1602
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb
1597
- - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/exec_error.rb
1598
- - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/execute_result.rb
1603
+ - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/execution.rb
1599
1604
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb
1600
1605
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb
1606
+ - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_error.rb
1607
+ - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
1601
1608
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb
1602
1609
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/local_env.rb
1603
1610
  - sub/eac_ruby_utils/lib/eac_ruby_utils/envs/process.rb
@@ -1743,6 +1750,7 @@ files:
1743
1750
  - sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
1744
1751
  - sub/eac_ruby_utils/spec/lib/eac_ruby_utils/custom_format_spec.rb
1745
1752
  - sub/eac_ruby_utils/spec/lib/eac_ruby_utils/enum_spec.rb
1753
+ - sub/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/command_spec.rb
1746
1754
  - sub/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb
1747
1755
  - sub/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/ssh_env_spec.rb
1748
1756
  - sub/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/extname_spec.rb
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/envs/command/exec_error'
4
-
5
- module EacRubyUtils
6
- module Envs
7
- class Command
8
- class ExecuteResult
9
- attr_reader :r, :options
10
-
11
- def initialize(result, options)
12
- @r = result
13
- @options = options
14
- end
15
-
16
- def result
17
- return exit_code_zero_result if exit_code_zero?
18
- return expected_error_result if expected_error?
19
-
20
- raise ::EacRubyUtils::Envs::Command::ExecError, 'Failed!'
21
- end
22
-
23
- def success?
24
- exit_code_zero? || expected_error?
25
- end
26
-
27
- private
28
-
29
- def exit_code_zero?
30
- r[:exit_code]&.zero?
31
- end
32
-
33
- def exit_code_zero_result
34
- r[options[:output] || :stdout]
35
- end
36
-
37
- def expected_error_result
38
- options[:exit_outputs][r[:exit_code]]
39
- end
40
-
41
- def expected_error?
42
- options[:exit_outputs].is_a?(Hash) && options[:exit_outputs].key?(r[:exit_code])
43
- end
44
- end
45
- end
46
- end
47
- end