class RestoreBundledWith::CLI

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/restore_bundled_with/cli.rb, line 5
def self.exit_on_failure?
  true
end

Public Instance Methods

delete() click to toggle source
# File lib/restore_bundled_with/cli.rb, line 56
def delete
  setup_logger(options)

  data = read_data(options)
  puts Lock.new(data).delete_bundled_with
rescue StandardError => e
  suggest_messages(options)
  raise e
end
fetch() click to toggle source
# File lib/restore_bundled_with/cli.rb, line 74
def fetch
  setup_logger(options)
  lock_file = Repository
              .new(options[:git_path], options[:git_options])
              .fetch_file(
                options[:lockfile],
                options[:ref],
                options[:new_line]
              )
  puts Lock
    .new(lock_file)
    .pick
rescue StandardError => e
  suggest_messages(options)
  raise e
end
logger() click to toggle source
# File lib/restore_bundled_with/cli.rb, line 110
def logger
  ::RestoreBundledWith.logger
end
method_missing(method, *args) click to toggle source

stackoverflow.com/a/23955971/104080

# File lib/restore_bundled_with/cli.rb, line 131
def method_missing(method, *args)
  self.class.start([self.class.default_command, method.to_s] + args)
end
read_data(options) click to toggle source
# File lib/restore_bundled_with/cli.rb, line 92
def read_data(options)
  data = \
    if options[:data]
      options[:data]
    elsif options[:file]
      File.read(options[:file])
    elsif !$stdin.tty?
      ARGV.clear
      ARGF.read
    end

  logger.info('input data')
  logger.info(data)
  raise NoInputError if !data || data.empty?

  data
end
restore() click to toggle source
# File lib/restore_bundled_with/cli.rb, line 30
def restore
  setup_logger(options)

  params = options.dup
  params[:file] = options[:lockfile] if !options[:data] && !options[:file]
  data = read_data(params)
  lock_file = Lock.restore(
    data,
    options[:lockfile],
    options[:ref],
    options[:git_path],
    options[:git_options],
    options[:new_line]
  )
  File.write(options[:lockfile], lock_file.body)
rescue StandardError => e
  suggest_messages(options)
  raise e
end
setup_logger(options) click to toggle source
# File lib/restore_bundled_with/cli.rb, line 114
def setup_logger(options)
  if options[:debug]
    logger.level = Logger::DEBUG
  elsif options[:verbose]
    logger.level = Logger::INFO
  end
  logger.debug(options)
end
suggest_messages(options) click to toggle source
# File lib/restore_bundled_with/cli.rb, line 123
def suggest_messages(options)
  logger.error 'Please report from here:'
  logger.error ISSUE_URL
  logger.error 'options:'
  logger.error options
end
version() click to toggle source
# File lib/restore_bundled_with/cli.rb, line 12
def version
  if options[:digit]
    print ::RestoreBundledWith::VERSION
  else
    puts "RestoreBundledWith version #{::RestoreBundledWith::VERSION}"
  end
end