eac_ruby_utils 0.108.0 → 0.109.0

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
  SHA256:
3
- metadata.gz: 7e29ceb1b90c374898bd5a0ef48d3852bbd9704ecc46de6964610fec9aeb7e2f
4
- data.tar.gz: 9dbb473fa3b24ac1354846da01f9c705f037fd59f4380500af97040953b8b69d
3
+ metadata.gz: f49997c361144d891925c3596cdc2ca37bcc485aa26aa287c4f7bfe529f3c553
4
+ data.tar.gz: 50f784d1c96e7432f5bcec9823899cb4407d1e2fe7465aee7bd605a6dfbfe6ea
5
5
  SHA512:
6
- metadata.gz: 13f74153fe16267d97f6edaa7aec5bef46d82f38fd17736b735bee01ae4669f71870b1da4c33f0827014a2dfb29c7eca8b59e44e71ebd2b89b8e1d7ae8243aab
7
- data.tar.gz: 6ace755da4832ffcd7586dab3cb16d4ff6ef582bd8a3a3907cb16b7c773fcc708ffbd0e3ec39b5df48b47fb26253541158a4ee7594a38847826ee0219106f73c
6
+ metadata.gz: 2cee869d6232e3b1b7027dc0a0927c9d3ae272e0177d4c90718ebaa279374b60cf42171006eae06df51a0c09967019ba7e9b175fd5635051ed196c4cc012bed8
7
+ data.tar.gz: fc6b4ed8fb837382ed816326d8930ce6fbb04a90fad68d5c48acf3516bd30f51eb4570ae04216129aa870627c8551500f480855a11981726e4dbb1ff05023cff
@@ -5,7 +5,7 @@ require 'shellwords'
5
5
 
6
6
  module EacRubyUtils
7
7
  module Envs
8
- class Command
8
+ module BaseCommand
9
9
  class AppendCommandOptions
10
10
  enable_method_class
11
11
  common_constructor :command, :command_line, :options
@@ -4,17 +4,18 @@ require 'eac_ruby_utils/struct'
4
4
 
5
5
  module EacRubyUtils
6
6
  module Envs
7
- class Command
7
+ module BaseCommand
8
8
  module Concat
9
9
  AND_OPERATOR = '&&'
10
10
  BEFORE_OPERATOR = ';'
11
11
  OR_OPERATOR = '||'
12
12
  PIPE_OPERATOR = '|'
13
13
 
14
+ # @param operator [Symbol]
15
+ # @return [EacRubyUtils::Envs::CompositeCommand]
14
16
  def concat(operator, other_command)
15
- duplicate_by_extra_options(concat: ::EacRubyUtils::Struct.new(
16
- operator: operator, command: other_command
17
- ))
17
+ require 'eac_ruby_utils/envs/composite_command'
18
+ ::EacRubyUtils::Envs::CompositeCommand.new(operator, self, other_command)
18
19
  end
19
20
 
20
21
  # @return [EacRubyUtils::Envs::Command]
@@ -34,14 +35,6 @@ module EacRubyUtils
34
35
  def pipe(other_command)
35
36
  concat(PIPE_OPERATOR, other_command)
36
37
  end
37
-
38
- private
39
-
40
- def append_concat(command)
41
- extra_options[:concat].if_present(command) do |v|
42
- "#{command} #{v.operator} #{v.command.command}"
43
- end
44
- end
45
38
  end
46
39
  end
47
40
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module EacRubyUtils
4
4
  module Envs
5
- class Command
5
+ module BaseCommand
6
6
  module Debugging
7
7
  def debug?
8
8
  ENV['DEBUG'].to_s.strip != ''
@@ -8,7 +8,7 @@ require 'pp'
8
8
 
9
9
  module EacRubyUtils
10
10
  module Envs
11
- class Command
11
+ module BaseCommand
12
12
  module Execution
13
13
  def execute!(options = {})
14
14
  options[:exit_outputs] = status_results.merge(options[:exit_outputs].presence || {})
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/hash/indifferent_access'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'shellwords'
6
+
7
+ module EacRubyUtils
8
+ module Envs
9
+ module BaseCommand
10
+ module ExtraOptions
11
+ # @return [ActiveSupport::HashWithIndifferentAccess]
12
+ def extra_options
13
+ @extra_options ||= {}.with_indifferent_access
14
+ end
15
+
16
+ def status_result(status_code, result)
17
+ duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
18
+ end
19
+
20
+ private
21
+
22
+ def status_results
23
+ extra_options[:status_results] ||= {}.with_indifferent_access
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'shellwords'
5
+
6
+ module EacRubyUtils
7
+ module Envs
8
+ module BaseCommand
9
+ require_sub __FILE__
10
+
11
+ common_concern do
12
+ enable_abstract_methods
13
+ include ::EacRubyUtils::Envs::BaseCommand::Concat
14
+ include ::EacRubyUtils::Envs::BaseCommand::Debugging
15
+ include ::EacRubyUtils::Envs::BaseCommand::Execution
16
+ include ::EacRubyUtils::Envs::BaseCommand::ExtraOptions
17
+ end
18
+
19
+ # @return [EacRubyUtils::Envs::BaseEnv]
20
+ def env
21
+ raise_abstract_method __method__
22
+ end
23
+
24
+ def command(options = {})
25
+ append_command_options(
26
+ env.command_line(command_line_without_env),
27
+ options
28
+ )
29
+ end
30
+
31
+ # @return [String]
32
+ def command_line_without_env(_options = {})
33
+ raise_abstract_method __method__
34
+ end
35
+
36
+ private
37
+
38
+ def escape(arg)
39
+ arg = arg.to_s
40
+ m = /^\@ESC_(.+)$/.match(arg)
41
+ m ? m[1] : Shellwords.escape(arg)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -12,18 +12,8 @@ module EacRubyUtils
12
12
  duplicate_by_extra_options(chdir: dir)
13
13
  end
14
14
 
15
- def status_result(status_code, result)
16
- duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
17
- end
18
-
19
15
  private
20
16
 
21
- attr_reader :extra_options
22
-
23
- def status_results
24
- extra_options[:status_results] ||= {}.with_indifferent_access
25
- end
26
-
27
17
  def append_chdir(command)
28
18
  extra_options[:chdir].present? ? "(cd '#{extra_options[:chdir]}' ; #{command} )" : command
29
19
  end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
- require 'shellwords'
4
+ require 'eac_ruby_utils/envs/base_command'
5
5
 
6
6
  module EacRubyUtils
7
7
  module Envs
8
8
  class Command
9
9
  require_sub __FILE__, include_modules: true, require_dependency: true
10
+ include ::EacRubyUtils::Envs::BaseCommand
10
11
 
11
12
  class << self
12
13
  # @param command [Array]
@@ -39,18 +40,11 @@ module EacRubyUtils
39
40
  "#{args} [ENV: #{env}]"
40
41
  end
41
42
 
42
- def command(options = {})
43
- append_command_options(
44
- env.command_line(command_line_without_env),
45
- options
46
- )
47
- end
48
-
49
43
  # @return [String]
50
44
  def command_line_without_env
51
45
  c = args
52
46
  c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
53
- append_chdir(append_concat(append_envvars(c)))
47
+ append_chdir(append_envvars(c))
54
48
  end
55
49
 
56
50
  protected
@@ -68,12 +62,6 @@ module EacRubyUtils
68
62
  def duplicate_by_extra_options(set_extra_options)
69
63
  duplicate(args, extra_options.merge(set_extra_options))
70
64
  end
71
-
72
- def escape(arg)
73
- arg = arg.to_s
74
- m = /^\@ESC_(.+)$/.match(arg)
75
- m ? m[1] : Shellwords.escape(arg)
76
- end
77
65
  end
78
66
  end
79
67
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/envs/base_command'
5
+
6
+ module EacRubyUtils
7
+ module Envs
8
+ class CompositeCommand
9
+ include ::EacRubyUtils::Envs::BaseCommand
10
+
11
+ enable_listable
12
+ lists.add_string :operator, '&&' => :and, ';' => :before, '||' => :or, '|' => :pipe
13
+
14
+ common_constructor :operator, :left_command, :right_command do
15
+ self.operator = self.class.lists.operator.value_validate!(operator.to_s)
16
+ end
17
+
18
+ # @return [EacRubyUtils::Envs::BaseEnv]
19
+ delegate :env, to: :left_command
20
+
21
+ # @return [String]
22
+ def command_line_without_env(_options = {})
23
+ ::Shellwords.join(['bash', '-c', bash_command])
24
+ end
25
+
26
+ # @return [String]
27
+ def bash_command
28
+ ['set', '-euo', 'pipefail', OPERATOR_BEFORE, left_command.command, operator,
29
+ right_command.command].join(' ')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.108.0'
4
+ VERSION = '0.109.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.108.0
4
+ version: 0.109.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-23 00:00:00.000000000 Z
11
+ date: 2022-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -139,14 +139,17 @@ files:
139
139
  - lib/eac_ruby_utils/custom_format.rb
140
140
  - lib/eac_ruby_utils/enum.rb
141
141
  - lib/eac_ruby_utils/envs.rb
142
+ - lib/eac_ruby_utils/envs/base_command.rb
143
+ - lib/eac_ruby_utils/envs/base_command/append_command_options.rb
144
+ - lib/eac_ruby_utils/envs/base_command/concat.rb
145
+ - lib/eac_ruby_utils/envs/base_command/debugging.rb
146
+ - lib/eac_ruby_utils/envs/base_command/execution.rb
147
+ - lib/eac_ruby_utils/envs/base_command/extra_options.rb
142
148
  - lib/eac_ruby_utils/envs/base_env.rb
143
149
  - lib/eac_ruby_utils/envs/command.rb
144
- - lib/eac_ruby_utils/envs/command/append_command_options.rb
145
- - lib/eac_ruby_utils/envs/command/concat.rb
146
- - lib/eac_ruby_utils/envs/command/debugging.rb
147
150
  - lib/eac_ruby_utils/envs/command/envvars.rb
148
- - lib/eac_ruby_utils/envs/command/execution.rb
149
151
  - lib/eac_ruby_utils/envs/command/extra_options.rb
152
+ - lib/eac_ruby_utils/envs/composite_command.rb
150
153
  - lib/eac_ruby_utils/envs/executable.rb
151
154
  - lib/eac_ruby_utils/envs/execution_error.rb
152
155
  - lib/eac_ruby_utils/envs/execution_result.rb