Class: AllGem::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/all-gem/cli.rb

Defined Under Namespace

Classes: Error, Options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:, stdin:) ⇒ CLI

Returns a new instance of CLI.



26
27
28
29
30
31
32
# File 'lib/all-gem/cli.rb', line 26

def initialize(stdout:, stderr:, stdin:)
  @stdout = stdout
  @stderr = stderr
  @stdin = stdin

  set_optparse
end

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



24
25
26
# File 'lib/all-gem/cli.rb', line 24

def op
  @op
end

#optsObject (readonly)

Returns the value of attribute opts.



24
25
26
# File 'lib/all-gem/cli.rb', line 24

def opts
  @opts
end

#stderrObject (readonly)

Returns the value of attribute stderr.



24
25
26
# File 'lib/all-gem/cli.rb', line 24

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



24
25
26
# File 'lib/all-gem/cli.rb', line 24

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



24
25
26
# File 'lib/all-gem/cli.rb', line 24

def stdout
  @stdout
end

Instance Method Details

#run(argv) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/all-gem/cli.rb', line 34

def run(argv)
  argv = @op.order(argv)

  command = argv[0] or raise Error.new("COMMAND is not specified.\n\n" + op.help)
  spec = gemspec_from_command(command)

  versions = versions_of(spec, opts)
  versions = filter_by_level(versions, opts)
  install! spec, versions

  # TODO: omit the same output
  # TODO: handle exit status
  versions.each do |v|
    stdout.puts "#{command}-#{v}"
    __skip__  = system(command, "_#{v}_", *argv[1..])
  end
end