Class: Gloo::Verbs::Execute

Inherits:
Core::Verb show all
Defined in:
lib/gloo/verbs/execute.rb

Constant Summary collapse

KEYWORD =
'execute'.freeze
KEYWORD_SHORT =
'exec'.freeze
MISSING_EXPR_ERR =
'Missing Expression!'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Verb

#params, #tokens

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Verb

#display_value, help, inherited, #initialize, #type_display

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Verb

Class Method Details

.doc_dataObject

Get the verb's documentation data.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gloo/verbs/execute.rb', line 59

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'Execute a shell command. This verb is not ' \
      'available in the Web app.',
    :syntax => [ 'exec {expression}' ],
    :parameters => [
      '{expression} — Evaluate the expression and execute in the shell.'
    ],
    :result => 'There is no result within gloo, any output is in the terminal.',
    :errors => [
      "#{MISSING_EXPR_ERR} — No expression is provided as parameter to the verb."
    ],
    :examples => <<~EXAMPLES.strip
      > exec 'rake test'
    EXAMPLES
  }
end

.keywordObject

Get the Verb's keyword.



41
42
43
# File 'lib/gloo/verbs/execute.rb', line 41

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb's keyword shortcut.



48
49
50
# File 'lib/gloo/verbs/execute.rb', line 48

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#runObject

Run the verb.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gloo/verbs/execute.rb', line 18

def run
  if @tokens.token_count < 2
    @engine.err MISSING_EXPR_ERR
    return
  end

  expr = Gloo::Expr::Expression.new( @engine, @tokens.params )
  cmd = expr.evaluate
  @engine.log.debug "starting cmd: #{cmd}"

  if OS.mac?
    pid = fork { exec( cmd ) }
    Process.wait pid
  else
    exec cmd
  end

  @engine.log.debug "done executing cmd: #{cmd}"
end