Class: RedmineInstaller::Command

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/redmine-installer/command.rb

Defined Under Namespace

Classes: BaseFormatter, FullFormatter, SilentFormatter

Constant Summary

Constants included from Utils

Utils::PROGRESSBAR_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#class_name, #create_dir, #env_user, #error, #logger, #ok, #pastel, #print_title, #prompt, #run_command

Constructor Details

#initialize(cmd, title: nil) ⇒ Command

Returns a new instance of Command.



9
10
11
12
13
# File 'lib/redmine-installer/command.rb', line 9

def initialize(cmd, title: nil)
  @cmd = cmd
  @title = title || cmd
  @formatter = $SILENT_MODE ? SilentFormatter.new : FullFormatter.new
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



7
8
9
# File 'lib/redmine-installer/command.rb', line 7

def cmd
  @cmd
end

#formatterObject (readonly)

Returns the value of attribute formatter.



7
8
9
# File 'lib/redmine-installer/command.rb', line 7

def formatter
  @formatter
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/redmine-installer/command.rb', line 7

def title
  @title
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/redmine-installer/command.rb', line 15

def run
  success = false

  logger.std("--> #{cmd}")

  formatter.print_title(title)

  status = Open3.popen2e(cmd) do |input, output, wait_thr|
    input.close

    output.each_line do |line|
      logger.std(line)
      formatter.print_line(line)
    end

    wait_thr.value
  end

  success = status.success?
rescue => e
  success = false
ensure
  formatter.print_end(success)
end