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.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pdk/cli/exec_group.rb', line 4 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
41 42 43 44 45 46 |
# File 'lib/pdk/cli/exec_group.rb', line 41 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pdk/cli/exec_group.rb', line 48 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
23 24 25 |
# File 'lib/pdk/cli/exec_group.rb', line 23 def parallel? @options[:parallel].nil? ? true : @options[:parallel] end |
#register(&block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pdk/cli/exec_group.rb', line 27 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 |