class Honyomi::CLI

Public Class Methods

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

Public Instance Methods

add(*args) click to toggle source
# File lib/honyomi/cli.rb, line 27
def add(*args)
  core = Core.new
  core.load_database

  if options[:title] && args.size > 1
    puts "Arguments is specified more than once, but there is --title option"
    return
  end

  args.each do |arg|
    begin
      book, status = core.add(arg, options)
    rescue Errno::ENOENT => e
      puts "Not found 'pdftotext' command (poppler, xpdf)"
      exit -1
    end

    unless book
      puts "Not exist: #{arg}"
      next
    end

    case status
    when :update
      puts "U #{book.id.to_s} #{book.title} (#{book.page_num} pages)"
    when :add
      puts "A #{book.id.to_s} #{book.title} (#{book.page_num} pages)"
    else
      raise
    end
  end
end
edit(*args) click to toggle source
# File lib/honyomi/cli.rb, line 76
def edit(*args)
  core = Core.new
  core.load_database

  begin 
    book_id = args[0].to_i
    core.edit(book_id, options)
    puts core.list([book_id])
  rescue HonyomiError => e
    puts e
    exit -1
  end
end
image(*args) click to toggle source
# File lib/honyomi/cli.rb, line 140
def image(*args)
  core = Core.new
  core.load_database

  args.each do |id|
    core.image(id.to_i, { verbose: true, delete: options[:delete] })
  end
end
init() click to toggle source
# File lib/honyomi/cli.rb, line 13
def init
  begin
    core = Core.new
    core.init_database
    puts "Create database to \"#{core.db_path}\""
  rescue Groonga::FileExists
    puts "Database already exists in \"#{core.db_path}\""
  end
end
invoke_command(task, *args) click to toggle source

Override method for support -h defined in /lib/thor/invocation.rb

Calls superclass method
# File lib/honyomi/cli.rb, line 160
def invoke_command(task, *args)
  if task.name == "help" && args == [[]]
    print "honyomi #{Honyomi::VERSION}\n\n"
  end
  
  if options[:help]
    CLI.task_help(shell, task.name)
  else
    super
  end
end
list(*args) click to toggle source
# File lib/honyomi/cli.rb, line 120
def list(*args)
  core = Core.new
  core.load_database

  puts core.list(args.map{|v| v.to_i }, options)
end
move(old_path, new_path) click to toggle source
# File lib/honyomi/cli.rb, line 150
def move(old_path, new_path)
  core = Core.new
  core.load_database

  core.move(old_path, new_path)
end
remove(*args) click to toggle source
# File lib/honyomi/cli.rb, line 91
def remove(*args)
  core = Core.new
  core.load_database

  args.each do |id|
    puts core.list([id.to_i])
    core.remove(id.to_i)
  end
end
web() click to toggle source
# File lib/honyomi/cli.rb, line 132
def web
  core = Core.new
  core.load_database      
  core.web(options)
end