class LambdaRubyBundler::CLI::OptionParser

Custom OptionParser which collects user-supplied options about the build. @api private

Constants

OPTIONS

Attributes

options[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 19
def initialize
  @options = defaults

  super { |builder| OPTIONS.each { |option| send(option, builder) } }
end

Public Instance Methods

parse!(*) click to toggle source
Calls superclass method
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 25
def parse!(*)
  super

  options[:dependencies_path] ||= build_default_dependencies_path(
    options[:output_path]
  )

  options
end

Private Instance Methods

app_path_option(builder) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 65
def app_path_option(builder)
  builder.on(
    '--app-path=APP_PATH',
    'Sets application path (relative to root) with the application code' \
    ' (defaults to current directory)',
    &assign_option(:app_path)
  )
end
assign_option(option) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 109
def assign_option(option)
  proc { |value| options[option] = value }
end
build_default_dependencies_path(output_path) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 48
def build_default_dependencies_path(output_path)
  File.join(
    File.dirname(output_path),
    [File.basename(output_path, '.*'), 'dependencies.zip'].join('-')
  )
end
cache_dir_option(builder) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 100
def cache_dir_option(builder)
  builder.on(
    '--cache-dir=CACHE_DIR',
    'Enables Cache Mode and uses chosen directory as target directory ' \
    'for the builds.',
    &assign_option(:cache_dir)
  )
end
defaults() click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 37
def defaults
  {
    root_path: Dir.pwd,
    app_path: '.',
    build_dependencies: true,
    dependencies_path: nil,
    output_path: 'build.zip',
    cache_dir: nil
  }
end
dependencies_path_option(builder) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 91
def dependencies_path_option(builder)
  builder.on(
    '--dependencies-path=APP_PATH',
    'Sets path for the dependencies layer package (defaults to ' \
    '{OUT_PATH}-dependencies.zip)',
    &assign_option(:dependencies_path)
  )
end
no_dependencies_option(builder) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 83
def no_dependencies_option(builder)
  builder.on(
    '--no-dependencies', 'Prevents building dependency layer'
  ) do |option|
    options[:build_dependencies] = option
  end
end
output_option(builder) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 74
def output_option(builder)
  builder.on(
    '--out=OUT_PATH',
    'Sets output path, to which the ZIP with the bundled code ' \
    'will be saved',
    &assign_option(:output_path)
  )
end
root_path_option(builder) click to toggle source
# File lib/lambda_ruby_bundler/cli/option_parser.rb, line 55
def root_path_option(builder)
  builder.on(
    '--root-path=ROOT_PATH',
    'Sets root path (containing Gemfile) of the application' \
    ' (defaults to current directory)'
  ) do |path|
    options[:root_path] = File.expand_path(path)
  end
end