Class: Mnenv::InstallCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/mnenv/commands/install_command.rb

Instance Method Summary collapse

Instance Method Details

#install(version = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mnenv/commands/install_command.rb', line 23

def install(version = nil)
  # If --list flag is provided, show available versions and exit
  return list_available_versions if options[:list]

  # If no version provided or interactive mode, prompt for selection
  if options[:interactive] || version.nil?
    version, source = select_installation_interactive
  else
    source = options[:source]
  end

  installer = InstallerFactory.create(version, source: source)

  if installer.installed?
    prompt = TTY::Prompt.new
    unless prompt.yes?("Version #{version} (source: #{source}) is already installed. Reinstall?")
      puts 'Installation cancelled.'
      return
    end
  end

  puts "Installing Metanorma #{version} (source: #{source})..."
  installer.install
  puts "Successfully installed Metanorma #{version} (source: #{source})!"
rescue Installer::InstallationError => e
  warn "Error: #{e.message}"
  exit 1
end