module Perkins::Build::Shell::Dsl

Constants

ANSI

Public Instance Methods

cd(path) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 41
def cd(path)
  cmd "cd #{path}", echo: true, timing: false
end
cmd(code, *args) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 10
def cmd(code, *args)
  options = args.last.is_a?(Hash) ? args.last : {}
  node = Cmd.new(code, *merge_options(args))
  options[:fold] ? fold(options[:fold]) { raw(node) } : raw(node)
end
echo(string, options = {}) click to toggle source

alias set export

# File lib/perkins/build/shell/dsl.rb, line 32
def echo(string, options = {})
  string = ansi(string, options) if options[:ansi]
  cmd "echo -e #{escape(string)}", { assert: false, echo: false, timing: false }.merge(options)
end
elif(*args, &block) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 57
def elif(*args, &block)
  raise InvalidParent.new(Elif, If, nodes.last.class) unless nodes.last.is_a?(If)
  args = merge_options(args)
  els_ = args.last.delete(:else)
  nodes.last.raw Elif.new(*args, &block)
  self.else(els_, args.last) if els_
  nodes.last
end
else(*args, &block) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 66
def else(*args, &block)
  raise InvalidParent.new(Else, If, nodes.last.class) unless nodes.last.is_a?(If)
  nodes.last.raw Else.new(*merge_options(args), &block)
  nodes.last
end
export(name, value, options = {}) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 23
def export(name, value, options = {})
  cmd "export #{name}=#{value}", { assert: false, timing: false }.merge(options)
end
file(path, content) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 45
def file(path, content)
  raw "echo #{escape(content)} > #{path}"
end
fold(name) { |self| ... } click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 72
def fold(name, &block)
  raw "travis_fold start #{name}"
  result = yield(self)
  raw "travis_fold end #{name}"
  result
end
if(*args, &block) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 49
def if(*args, &block)
  args = merge_options(args)
  els_ = args.last.delete(:else)
  nodes << If.new(*args, &block)
  self.else(els_, args.last) if els_
  nodes.last
end
newline() click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 37
def newline
  raw 'echo'
end
raw(code, *args) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 16
def raw(code, *args)
  args = merge_options(args)
  pos = args.last.delete(:pos) || -1
  node = code.is_a?(Node) ? code : Node.new(code, *args)
  nodes.insert(pos, node)
end
script(*args, &block) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 5
def script(*args, &block)
  nodes << Script.new(*merge_options(args), &block)
  nodes.last
end
set(name, value, options = {}) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 27
def set(name, value, options = {})
  cmd "export #{name}=#{value}", { assert: false, timing: false }.merge(options)
end

Private Instance Methods

ansi(string, options) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 93
def ansi(string, options)
  keys = Array(options[:ansi])
  prefix = keys.map { |key| ANSI[key] }
  lines = string.split("\n").map do |line|
    line.strip.empty? ? line : [prefix, line, ANSI[:reset]].flatten.join
  end
  lines.join("\n")
end
merge_options(args, options = {}) click to toggle source
# File lib/perkins/build/shell/dsl.rb, line 81
def merge_options(args, options = {})
  options = (args.last.is_a?(Hash) ? args.pop : {}).merge(options)
  args << self.options.merge(options)
end