Sha256: 630291b2d72be092a5ebcf556f78019da51a3240aa29b37e421b546f20d99f61

Contents?: true

Size: 667 Bytes

Versions: 23

Compression:

Stored size: 667 Bytes

Contents

require 'pre-commit/checks/plugin'
require 'shellwords'

module PreCommit
  module Checks
    class Shell < Plugin

    private

      def execute(*args)
        options = args.last.is_a?(::Hash) ? args.pop : {}
        args = build_command(*args)
        execute_raw(args, options)
      end

      def build_command(*args)
        args.flatten.map do |arg|
          arg = arg.shellescape if arg != '|' && arg != '&&' && arg != '||'
          arg
        end.join(" ")
      end

      def execute_raw(command, options = {})
        result = `#{command} 2>&1`
        $?.success? == (options.fetch(:success_status, true)) ? nil : result
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
pre-commit-0.40.0 lib/pre-commit/checks/shell.rb
pre-commit-0.39.0 lib/pre-commit/checks/shell.rb
pre-commit-0.38.1 lib/pre-commit/checks/shell.rb
pre-commit-0.38.0 lib/pre-commit/checks/shell.rb
pre-commit-0.37.0 lib/pre-commit/checks/shell.rb
pre-commit-0.36.0 lib/pre-commit/checks/shell.rb
pre-commit-0.35.0 lib/pre-commit/checks/shell.rb
pre-commit-0.34.0 lib/pre-commit/checks/shell.rb
pre-commit-0.33.0 lib/pre-commit/checks/shell.rb
pre-commit-0.32.0 lib/pre-commit/checks/shell.rb
pre-commit-0.31.0 lib/pre-commit/checks/shell.rb
pre-commit-0.30.0 lib/pre-commit/checks/shell.rb
pre-commit-0.29.0 lib/pre-commit/checks/shell.rb
pre-commit-0.28.0 lib/pre-commit/checks/shell.rb
pre-commit-0.27.0 lib/pre-commit/checks/shell.rb
pre-commit-0.26.0 lib/pre-commit/checks/shell.rb
pre-commit-0.25.0 lib/pre-commit/checks/shell.rb
pre-commit-0.24.0 lib/pre-commit/checks/shell.rb
pre-commit-0.23.0 lib/pre-commit/checks/shell.rb
pre-commit-0.22.1 lib/pre-commit/checks/shell.rb