Class: Gel::Command::Lock

Inherits:
Gel::Command show all
Defined in:
lib/gel/command/lock.rb

Instance Attribute Summary

Attributes inherited from Gel::Command

#reraise

Instance Method Summary collapse

Methods inherited from Gel::Command

extract_word, handle_error, run

Instance Method Details

#run(command_line) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gel/command/lock.rb', line 4

def run(command_line)
  options = {}

  mode = :hold
  strict = false
  overrides = {}

  until command_line.empty?
    case argument = command_line.shift
    when "--strict"; strict = true
    when "--major"; mode = :major
    when "--minor"; mode = :minor
    when "--patch"; mode = :patch
    when "--hold"; mode = :hold
    when /\A--lockfile(?:=(.*))?\z/
      options[:lockfile] = $1 || command_line.shift
    when /\A((?!-)[A-Za-z0-9_-]+)(?:(?:[\ :\/]|(?=[<>~=]))([<>~=,\ 0-9A-Za-z.-]+))?\z/x
      overrides[$1] = Gel::Support::GemRequirement.new($2 ? $2.split(/\s+(?=[0-9])|\s*,\s*/) : [])
    else
      raise "Unknown argument #{argument.inspect}"
    end
  end

  require_relative "../pub_grub/preference_strategy"
  options[:preference_strategy] = lambda do |loader|
    Gel::PubGrub::PreferenceStrategy.new(loader, overrides, bump: mode, strict: strict)
  end

  Gel::Environment.lock(output: $stderr, **options)
end