Sha256: 3abe5b024cf4532aa65e8b48f4478e7e8f1806f448d42cba389877b65817c42c

Contents?: true

Size: 1.17 KB

Versions: 70

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/envs/base_command'

module EacRubyUtils
  module Envs
    class CompositeCommand
      include ::EacRubyUtils::Envs::BaseCommand

      enable_listable
      lists.add_string :operator, '&&' => :and, ';' => :before, '||' => :or, '|' => :pipe

      common_constructor :operator, :left_command, :right_command do
        self.operator = self.class.lists.operator.value_validate!(operator.to_s)
      end

      # @return [EacRubyUtils::Envs::BaseEnv]
      delegate :env, to: :left_command

      # @return [String]
      def command_line_without_env(_options = {})
        ::Shellwords.join(['bash', '-c', bash_command])
      end

      # @return [String]
      def bash_command
        ['set', '-euo', 'pipefail', OPERATOR_BEFORE, left_command_line, operator,
         right_command_line].join(' ')
      end

      def left_command_line
        left_command.command_line_without_env
      end

      def right_command_line
        if right_command.env == left_command.env
          right_command.command_line_without_env
        else
          right_command.command
        end
      end
    end
  end
end

Version data entries

70 entries across 70 versions & 2 rubygems

Version Path
eac_ruby_utils-0.124.0 lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.97.2 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.123.0 lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/envs/composite_command.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/envs/composite_command.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/composite_command.rb