Class: Bookshelf::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/bookshelf/cli.rb

Constant Summary collapse

FORMATS =
%w[pdf html epub]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Cli

Returns a new instance of Cli.



11
12
13
14
15
16
17
# File 'lib/bookshelf/cli.rb', line 11

def initialize(args = [], options = {}, config = {})
  if (config[:current_task] || config[:current_command]).name == "new" && args.empty?
    raise Error, "The e-Book path is required. For details run: bookshelf help new"
  end

  super
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/bookshelf/cli.rb', line 7

def self.exit_on_failure?
  true
end

Instance Method Details

#checkObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bookshelf/cli.rb', line 48

def check
  result = []

  result << {
    :description => "Prince XML: Converts HTML files into PDF files.",
    :installed => Bookshelf::Dependency.prince?
  }

  result.each do |result|
    text = color(result[:name], :blue)
    text << "\n" << result[:description]
    text << "\n" << (result[:installed] ? color("Installed.", :green) : color("Not installed.", :red))
    text << "\n"

    say(text)
  end
end

#exportObject



30
31
32
33
34
35
36
37
# File 'lib/bookshelf/cli.rb', line 30

def export
  if options[:only] && !FORMATS.include?(options[:only])
    raise Error, "The --only option need to be one of: #{FORMATS.join(", ")}"
  end

  book_dir = Pathname.new("text")
  Bookshelf::Exporter.run(book_dir, options)
end

#new(path) ⇒ Object



21
22
23
24
25
# File 'lib/bookshelf/cli.rb', line 21

def new(path)
  generator = Generator.new
  generator.destination_root = path
  generator.invoke_all
end

#statsObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/bookshelf/cli.rb', line 67

def stats
  stats = Bookshelf::Stats.new(Bookshelf.root_dir)

  say [
    "Chapters: #{stats.chapters}",
    "Words: #{stats.words}",
    "Images: #{stats.images}",
    "Links: #{stats.links}"
  ].join("\n")
end

#versionObject



42
43
44
# File 'lib/bookshelf/cli.rb', line 42

def version
  say "Bookshelf version #{Version::STRING}"
end