Class: PDK::CLI::ExecGroup
- Inherits:
-
Object
- Object
- PDK::CLI::ExecGroup
- Defined in:
- lib/pdk/cli/exec_group.rb
Instance Method Summary collapse
- #add_spinner(message, opts = {}) ⇒ Object
- #exit_code ⇒ Object
-
#initialize(message, opts = {}) ⇒ ExecGroup
constructor
A new instance of ExecGroup.
- #parallel? ⇒ Boolean
- #register(&block) ⇒ Object
Constructor Details
#initialize(message, opts = {}) ⇒ ExecGroup
Returns a new instance of ExecGroup.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pdk/cli/exec_group.rb', line 6 def initialize(, opts = {}) require 'pdk/cli/util' @options = opts.merge(PDK::CLI::Util.spinner_opts_for_platform) if PDK::CLI::Util.interactive? require 'pdk/cli/util/spinner' @spinner = if parallel? TTY::Spinner::Multi.new("[:spinner] #{}", @options) else TTY::Spinner.new("[:spinner] #{}", @options) end @spinner.auto_spin end @threads_or_procs = [] @exit_codes = [] end |
Instance Method Details
#add_spinner(message, opts = {}) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/pdk/cli/exec_group.rb', line 43 def add_spinner(, opts = {}) require 'pdk/cli/util' return unless PDK::CLI::Util.interactive? @spinner.register("[:spinner] #{}", @options.merge(opts).merge(PDK::CLI::Util.spinner_opts_for_platform)) end |
#exit_code ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pdk/cli/exec_group.rb', line 50 def exit_code if parallel? @threads_or_procs.each(&:join) else @exit_codes = @threads_or_procs.map(&:call) end exit_code = @exit_codes.max if exit_code.zero? && @spinner @spinner.success elsif @spinner @spinner.error end exit_code end |
#parallel? ⇒ Boolean
25 26 27 |
# File 'lib/pdk/cli/exec_group.rb', line 25 def parallel? @options[:parallel].nil? ? true : @options[:parallel] end |
#register(&block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pdk/cli/exec_group.rb', line 29 def register(&block) raise PDK::CLI::FatalError, _('No block registered') unless block_given? @threads_or_procs << if parallel? Thread.new do GettextSetup.initialize(File.absolute_path('../../../locales', File.dirname(__FILE__))) GettextSetup.negotiate_locale!(GettextSetup.candidate_locales) @exit_codes << yield end else block end end |