Class: Packs::Private::InteractiveCli::PackSelector

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/packs/private/interactive_cli/pack_selector.rb

Class Method Summary collapse

Class Method Details

.single_or_all_pack_multi_select(prompt, question_text: 'Please use space to select one or more packs') ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/packs/private/interactive_cli/pack_selector.rb', line 33

def self.single_or_all_pack_multi_select(prompt, question_text: 'Please use space to select one or more packs')
  pack_selection = T.let(prompt.multi_select(
    question_text,
    Packs.all.to_h { |t| [t.name, t] },
    filter: true,
    per_page: 10,
    show_help: :always
  ), T::Array[Packs::Pack])

  while pack_selection.empty?
    prompt.error(
      'No packs were selected, please select one or more packs using the space key before pressing enter.'
    )

    pack_selection = single_or_all_pack_multi_select(prompt, question_text: question_text)
  end

  pack_selection
end

.single_pack_select(prompt, question_text: 'Please use space to select a pack') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/packs/private/interactive_cli/pack_selector.rb', line 10

def self.single_pack_select(prompt, question_text: 'Please use space to select a pack')
  packs = Packs.all.to_h { |t| [t.name, t] }

  pack_selection = T.let(prompt.select(
    question_text,
    packs,
    filter: true,
    per_page: 10,
    show_help: :always
  ), T.nilable(Packs::Pack))

  while pack_selection.nil?
    prompt.error(
      'No packs were selected, please select a pack using the space key before pressing enter.'
    )

    pack_selection = single_pack_select(prompt, question_text: question_text)
  end

  pack_selection
end