class Appbundler::CLI

Attributes

argv[R]
bin_path[R]
bundle_path[R]
gems[R]

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/appbundler/cli.rb, line 60
def initialize(argv)
  @argv = argv
  super()
end
run(argv) click to toggle source
# File lib/appbundler/cli.rb, line 47
def self.run(argv)
  cli = new(argv)
  cli.handle_options
  cli.validate!
  cli.run
end

Public Instance Methods

err(message) click to toggle source
# File lib/appbundler/cli.rb, line 111
def err(message)
  $stderr.print("#{message}\n")
end
handle_options() click to toggle source
# File lib/appbundler/cli.rb, line 65
def handle_options
  parse_options(@argv)
end
run() click to toggle source
# File lib/appbundler/cli.rb, line 99
def run
  gems.each do |g|
    app = App.new(bundle_path, bin_path, g)
    created_stubs = app.write_executable_stubs
    created_stubs.each do |real_executable_path, stub_path|
      $stdout.puts "Generated binstub #{stub_path} => #{real_executable_path}"
    end
    created_lockfile = app.write_merged_lockfiles(without: config[:without])
    $stdout.puts "Generated merged lockfile at #{created_lockfile}" if created_lockfile
  end
end
usage_and_exit!() click to toggle source
# File lib/appbundler/cli.rb, line 115
def usage_and_exit!
  err(banner)
  exit 1
end
validate!() click to toggle source
# File lib/appbundler/cli.rb, line 69
def validate!
  if cli_arguments.size < 2
    usage_and_exit!
  else
    @bundle_path = File.expand_path(cli_arguments[0])
    @bin_path = File.expand_path(cli_arguments[1])
    @gems = cli_arguments[2..-1]
    @gems = [ nil ] if @gems.empty?
    verify_bundle_path
    verify_bin_path
  end
end
verify_bin_path() click to toggle source
# File lib/appbundler/cli.rb, line 92
def verify_bin_path
  if !File.directory?(bin_path)
    err("BINSTUB_DIR `#{bin_path}' is not a directory or doesn't exist")
    usage_and_exit!
  end
end
verify_bundle_path() click to toggle source
# File lib/appbundler/cli.rb, line 82
def verify_bundle_path
  if !File.directory?(bundle_path)
    err("BUNDLE_DIR `#{bundle_path}' is not a directory or doesn't exist")
    usage_and_exit!
  elsif !File.exist?(File.join(bundle_path, "Gemfile.lock"))
    err("BUNDLE_DIR does not contain required Gemfile.lock")
    usage_and_exit!
  end
end