Class: Packs::Private::InteractiveCli::TeamSelector

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

Class Method Summary collapse

Class Method Details

.multi_select(prompt, question_text: 'Please use space to select team owners') ⇒ Object



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

def self.multi_select(prompt, question_text: 'Please use space to select team owners')
  teams = CodeTeams.all.to_h { |t| [t.name, t] }

  team_selection = T.let(prompt.multi_select(
    question_text,
    teams,
    filter: true,
    per_page: 10,
    show_help: :always
  ), T::Array[CodeTeams::Team])

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

    team_selection = multi_select(prompt, question_text: question_text)
  end

  team_selection
end

.single_select(prompt, question_text: 'Please use space to select a team owner') ⇒ Object



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

def self.single_select(prompt, question_text: 'Please use space to select a team owner')
  teams = CodeTeams.all.sort_by(&:name).to_h { |t| [t.name, t] }
  return nil if teams.count == 0

  team_selection = T.let(prompt.select(
    question_text,
    teams,
    filter: true,
    per_page: 10,
    show_help: :always
  ), T.nilable(CodeTeams::Team))

  while team_selection.nil?
    prompt.error(
      'No owners were selected, please select an owner using the space key before pressing enter.'
    )

    team_selection = single_select(prompt, question_text: question_text)
  end

  team_selection
end