class Commands::ImportCommand

Import path(s) to target (default is current working dir):

tvshow import /some/path /some/other/path -o /some/out/path --verbose

Strategy used to «copy» files can be one of: ln_s (default), ln and copy

Usage: tvshow import [TARGETs] {OPTIONS}
    -o, --output [OUTPUT]            Path where files are copied
        --strategy [ln_s|copy|ln]    Strategy used to "copy" files
        --verbose                    Verbose
    -h, --help                       Display this screen

Public Class Methods

Commands::ImportCommand.execute() → nil click to toggle source

Execute command

# File lib/commands/import_command.rb, line 22
def self.execute
  begin
    input = self.parse
  rescue OptionParser::InvalidOption, ArgumentError, Errno::ENOENT => e
    App.exit_on_error(e, 22) # EINVAL
  end

  input.arguments.each do |path|
    ranger = Ranger.new(path, input.options[:output])
    ranger.method  = input.options[:method]
    ranger.verbose = input.options[:verbose]
    begin
      ranger.run
    rescue Errno::ENOENT => e
      App.exit_on_error(e, 2) # ENOENT
    end
  end
  return
end
Commands::ImportCommand.make_parser(Hash options) → CLI::Input click to toggle source

Prepare a parser

# File lib/commands/import_command.rb, line 65
def self.make_parser(options)
  methods = [options[:method], :copy, :ln]

  parser = CLI::Input.new do |opts|
    opts.from_command(self).make_banner('[TARGETs] {OPTIONS}')
    opts.on("-o [OUTPUT]", "--output [OUTPUT]", 'Path where files are copied') do |v|
      options[:output] = Pathname.new(v).realpath
    end
    opts.on("--strategy %s" % methods.cli_options, 'Strategy used to "copy" files') do |m|
      if !methods.include?(m.to_sym)
        raise ArgumentError.new('Unexpected method "%s"' % m)
      end
      options[:method] = m.to_sym
    end
    opts.on('--verbose', 'Verbose') { options[:verbose] = true }
    opts.add_help
  end
  return parser
end
Commands::ImportCommand.parse() → OpenStruct click to toggle source

Parse command line options

# File lib/commands/import_command.rb, line 46
def self.parse
  options = {:method  => :ln_s,
             :verbose => false,
             :output  => Pathname.new('.').realpath }

  self.make_parser(options).parse!
  options = self.make_options(options)

  if options.arguments.length == 0
    raise ArgumentError.new('Required target(s) missing')
  else
    return options
  end
end