Sha256: 7b5654e6648d0b5b05f7f2ff3cd373edc7fa61331c2401a7247e1ae91b6db8bd

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

module Wukong
  class Runner

    # Provides methods for executing commandlines.
    module CommandRunner

      private

      # Execute a command composed of the given parts.
      #
      # Will print the command instead if the <tt>--dry_run</tt>
      # option was given.
      #
      # Will *not* raise an error if the command fails.
      #
      # @param [Array<String>] argv
      def execute_command(*argv)
        command = argv.flatten.reject(&:blank?).join(" \\\n    ")
        if settings[:dry_run]
          log.info("Dry run:")
          puts command
        else
          output = `#{command}`
          puts output unless output.empty?
        end
      end

      # Execute a command composed of the given parts.
      #
      # Will print the command instead if the <tt>--dry_run</tt>
      # option was given.
      #
      # *Will* raise an error if the command fails.
      #
      # @param [Array<String>] argv
      def execute_command!(*argv)
        execute_command(argv)
        raise Error.new("Command failed!") unless $?.success?
      end
      
    end

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
ul-wukong-4.1.1 lib/wukong/runner/command_runner.rb
ul-wukong-4.1.0 lib/wukong/runner/command_runner.rb
wukong-4.0.0 lib/wukong/runner/command_runner.rb