Class: Rpremote::MrbgemsCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/rpremote/mrbgems_command.rb

Constant Summary collapse

DEFAULT_PATH =
Mrbgems::DEFAULT_PATH

Class Method Summary collapse

Class Method Details

.run(args, output: $stdout, mrbgems: Mrbgems) ⇒ Object

Raises:

  • (ArgumentError)


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

def self.run(args, output: $stdout, mrbgems: Mrbgems)
  command = args.shift
  options = { path: DEFAULT_PATH, lock_path: nil }
  OptionParser.new do |opts|
    opts.on("--file FILE") { |value| options[:path] = value }
    opts.on("--lockfile FILE") { |value| options[:lock_path] = value }
  end.parse!(args)
  raise ArgumentError, "mrbgems does not accept arguments" unless args.empty?

  manager = mrbgems.new(**options)
  case command
  when "check"
    dependencies = manager.check
    output.puts("checked #{dependencies.length} mrbgems: #{manager.path}")
  when "list"
    list(manager, output)
  when "lock", "update"
    result = manager.lock(update: command == "update")
    output.puts("locked #{result.fetch("gems").length} mrbgems: #{manager.lock_path}")
  else
    raise ArgumentError, "unknown mrbgems command: #{command || "(none)"}"
  end
end