Sha256: 27f2c125e9da50bd3ee9a373f37b15f83b9cf0d1aeda86a0cc5c4b5203973a84
Contents?: true
Size: 1 KB
Versions: 17
Compression:
Stored size: 1 KB
Contents
# frozen_string_literal: true module Conductor # Command runner class Command attr_reader :args, :path def initialize(command) parts = Shellwords.split(command) self.path = parts[0] self.args = parts[1..].join(" ") end def path=(path) @path = if %r{^[%/]}.match?(path) File.expand_path(path) else which = TTY::Which.which(path) which || path end end def args=(array) @args = if array.is_a?(Array) array.join(" ") else array end end def run stdin = Conductor.stdin raise "Command path not found" unless @path use_stdin = true if /\$\{?file\}?/.match?(args) use_stdin = false args.sub!(/\$\{?file\}?/, %("#{Env.env[:filepath]}")) else raise "No input" unless stdin end if use_stdin `echo #{Shellwords.escape(stdin)} | #{Env} #{path} #{args}` else `#{Env} #{path} #{args}` end end end end
Version data entries
17 entries across 17 versions & 1 rubygems