class Chid::Commands::Workstation::Create

Public Instance Methods

run() click to toggle source
# File lib/chid/commands/workstation/create.rb, line 26
def run
  workstation_name = get_workstation_name
  result           = ::ChidConfig.on_osx { select_apps_on_osx }

  if result.empty?
    puts "\nYou did not select any App, please try again."
    return
  end

  chid_config.create_workstation(workstation_name, result)

  puts "\n#{workstation_name} workstation was created!"
end

Private Instance Methods

chid_config() click to toggle source
# File lib/chid/commands/workstation/create.rb, line 58
def chid_config
  ::ChidConfig.new
end
choice_in_option_app_names?(choice) click to toggle source
# File lib/chid/commands/workstation/create.rb, line 93
def choice_in_option_app_names?(choice)
  DidYouMean::SpellChecker
    .new(dictionary: option_app_names)
    .correct(choice).any?
end
default_choices(choices) click to toggle source
# File lib/chid/commands/workstation/create.rb, line 82
def default_choices(choices)
  return unless option_app_names

  choices
    .flatten
    .each_with_object([])
    .each_with_index do |(choice, memo), index|
    memo << index + 1 if choice_in_option_app_names?(choice)
  end
end
get_workstation_name() click to toggle source
# File lib/chid/commands/workstation/create.rb, line 42
def get_workstation_name
  return option_name if option_name

  puts 'tell me the name of the new workstation'
  print "> "
  STDIN.gets.strip
end
option_app_names() click to toggle source
# File lib/chid/commands/workstation/create.rb, line 54
def option_app_names
  options['-app_names']
end
option_name() click to toggle source
# File lib/chid/commands/workstation/create.rb, line 50
def option_name
  options['-name']&.first&.strip
end
osx_application_names() click to toggle source
# File lib/chid/commands/workstation/create.rb, line 73
def osx_application_names
  osx_application_names = %x{ls /applications}.strip

  osx_application_names
    .gsub(/\n/, ' - ')
    .gsub('.app', '')
    .split(' - ')
end
select_apps_on_osx() click to toggle source
# File lib/chid/commands/workstation/create.rb, line 62
def select_apps_on_osx
  prompt = TTY::Prompt.new

  choices = osx_application_names

  default_choices = default_choices(choices)

  prompt.multi_select('select all apps for that workstation?', choices, default: default_choices)
end