Module: Pwrake::FileUtils

Included in:
Rake::DSL
Defined in:
lib/pwrake/branch/file_utils.rb

Class Method Summary collapse

Class Method Details

.bq(*cmd, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pwrake/branch/file_utils.rb', line 29

def bq(*cmd, &block)
  options = (Hash === cmd.last) ? cmd.pop : {}
  unless block_given?
    show_command = cmd.join(" ")
    show_command = show_command[0,42] + "..."
    block = lambda { |ok, status|
      ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
    }
  end
  if RakeFileUtils.verbose_flag == :default
    options[:verbose] = true
  else
    options[:verbose] ||= RakeFileUtils.verbose_flag
  end
  options[:noop] ||= RakeFileUtils.nowrite_flag
  Rake.rake_check_options options, :noop, :verbose
  Rake.rake_output_message cmd.join(" ") if options[:verbose]
  unless options[:noop]
    res,status = Pwrake::FileUtils.pwrake_backquote(*cmd)
    block.call(res, status)
  end
  res
end

.pwrake_backquote(cmd) ⇒ Object

Pwrake version of backquote command



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pwrake/branch/file_utils.rb', line 67

def pwrake_backquote(cmd)
  conn = Pwrake::Shell.current
  if conn.kind_of?(Pwrake::Shell)
    res    = conn.backquote(*cmd)
    status = Rake::PseudoStatus.new(conn.status)
  else
    res    = `#{cmd}`
    status = $?
    status = Rake::PseudoStatus.new(1) if status.nil?
  end
  [res,status]
end

.pwrake_system(*cmd) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pwrake/branch/file_utils.rb', line 53

def pwrake_system(*cmd)
  conn = Pwrake::Shell.current
  if conn.kind_of?(Pwrake::Shell)
    res    = conn.system(*cmd)
    status = Rake::PseudoStatus.new(conn.status)
  else
    res    = system(*cmd)
    status = $?
    status = Rake::PseudoStatus.new(1) if !res && status.nil?
  end
  [res,status]
end

.sh(*cmd, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pwrake/branch/file_utils.rb', line 6

def sh(*cmd, &block)
  options = (Hash === cmd.last) ? cmd.pop : {}
  unless block_given?
    show_command = cmd.join(" ")
    show_command = show_command[0,42] + "..."
    block = lambda { |ok, status|
      ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
    }
  end
  if RakeFileUtils.verbose_flag == :default
    options[:verbose] = true
  else
    options[:verbose] ||= RakeFileUtils.verbose_flag
  end
  options[:noop] ||= RakeFileUtils.nowrite_flag
  Rake.rake_check_options options, :noop, :verbose
  Rake.rake_output_message cmd.join(" ") if options[:verbose]
  unless options[:noop]
    res,status = Pwrake::FileUtils.pwrake_system(*cmd)
    block.call(res, status)
  end
end