Module: Perkins::Build::Shell::Dsl

Included in:
Group
Defined in:
lib/perkins/build/shell/dsl.rb

Instance Method Summary collapse

Instance Method Details

#cd(path) ⇒ Object



41
42
43
# File 'lib/perkins/build/shell/dsl.rb', line 41

def cd(path)
  cmd "cd #{path}", echo: true, timing: false
end

#cmd(code, *args) ⇒ Object



10
11
12
13
14
# 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 = {}) ⇒ Object

alias set export



32
33
34
35
# 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) ⇒ Object

Raises:



57
58
59
60
61
62
63
64
# 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) ⇒ Object

Raises:



66
67
68
69
70
# 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 = {}) ⇒ Object



23
24
25
# 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) ⇒ Object



45
46
47
# File 'lib/perkins/build/shell/dsl.rb', line 45

def file(path, content)
  raw "echo #{escape(content)} > #{path}"
end

#fold(name, &block) ⇒ Object



72
73
74
75
76
77
# 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) ⇒ Object



49
50
51
52
53
54
55
# 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

#newlineObject



37
38
39
# File 'lib/perkins/build/shell/dsl.rb', line 37

def newline
  raw 'echo'
end

#raw(code, *args) ⇒ Object



16
17
18
19
20
21
# 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) ⇒ Object



5
6
7
8
# 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 = {}) ⇒ Object



27
28
29
# 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