class Lapidarius::CLI

Constants

HELP_FLAGS

Attributes

name[R]
remote[R]
version[R]

Public Class Methods

new(args: [], io: STDOUT, command: Command, cutter: Cutter, tree: Tree) click to toggle source
# File lib/lapidarius/cli.rb, line 10
def initialize(args: [], io: STDOUT, command: Command, cutter: Cutter, tree: Tree)
  @args = args
  @io = io
  @command = command
  @cutter = cutter
  @tree = tree
  @name = @args.shift unless help?
  parser.parse!(@args)
end

Public Instance Methods

call() click to toggle source
# File lib/lapidarius/cli.rb, line 20
def call
  @io.puts out
end

Private Instance Methods

cutter() click to toggle source
# File lib/lapidarius/cli.rb, line 24
        def cutter
  @cutter.new(name: @name, cmd_klass: @command, version: @version, remote: @remote)
end
help?() click to toggle source
# File lib/lapidarius/cli.rb, line 59
        def help?
  HELP_FLAGS.any? { |h| @args.first == h }
end
out() click to toggle source
# File lib/lapidarius/cli.rb, line 28
        def out
  return unless @name
  gem = cutter.call
  @tree::new(gem, @quiet).out
rescue Gem::NotInstalledError, Gem::KindError => e
  e.message
end
parser() click to toggle source
# File lib/lapidarius/cli.rb, line 36
        def parser
  OptionParser.new do |opts|
    opts.banner = %q{Usage: lapidarius sinatra --version=1.4.7 --remote --quiet}

    opts.on("-vVERSION", "--version=VERSION", "Specify the gem version to cut") do |version|
      @version = version
    end

    opts.on("-r", "--remote", "Fetch gem remotely") do |remote|
      @remote = true
    end

    opts.on("-q", "--quiet", "Hide dependencies tree") do |quiet|
      @quiet = true
    end

    opts.on(*HELP_FLAGS, "Prints this help") do
      @io.puts opts
      exit
    end
  end
end