Class: Yapo::Commands::Exec

Inherits:
Yapo::Command show all
Defined in:
lib/yapo/commands/exec.rb

Instance Method Summary collapse

Methods inherited from Yapo::Command

#command, #exec_exist?, #generator, #pastel, #platform, #prompt, #screen, #which

Constructor Details

#initialize(command, options) ⇒ Exec

Returns a new instance of Exec.



11
12
13
14
# File 'lib/yapo/commands/exec.rb', line 11

def initialize(command, options)
  @command = command
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/yapo/commands/exec.rb', line 16

def execute(input: $stdin, output: $stdout)
  begin
    commands_helper = Yapo::Helpers::Commands.new
    validations_helper = Yapo::Helpers::Validations.new
    
    validations_helper.verify_version
    if @options[:prepend] && !@command.nil?
      commands = commands_helper.prepend_commands(@options[:prepend], @command)
    else
      commands = commands_helper.get_commands_for(@command)
    end
    
    if commands.nil?
      msg = "You must include an entry for #{@command} in .yapo.yml."
      raise Yapo::Helpers::CustomErrors::ValidationError.new(nil, msg)
    else
      Yapo::Helpers::Teletype.new.bash_commands(commands)
    end

    output.puts "OK"
  rescue Yapo::Helpers::CustomErrors::ValidationError
    output.puts "ERROR:ValidationError"
  rescue Yapo::Helpers::CustomErrors::SyntaxError
    output.puts "ERROR:SyntaxError"
  rescue Yapo::Helpers::CustomErrors::CommandError
    output.puts "ERROR:CommandError"
  end
end