Class: Bookmaker::Cli

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

Constant Summary collapse

FORMATS =
%w[pdf draft proof html epub mobi txt]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Cli.



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

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

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/bookmaker/cli.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#create(path) ⇒ Object



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

def create(path)
  puts "Bookmaker -- A Million Monkeys Writing Your Masterpiece."
  generator = Generator.new
  generator.destination_root = path.squish.gsub(' ','-')
  generator.invoke_all
end

#exportObject



32
33
34
35
36
37
38
# File 'lib/bookmaker/cli.rb', line 32

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

#statsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bookmaker/cli.rb', line 47

def stats
  inside_ebook!
  stats = Bookmaker::Stats.new(root_dir)

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

#versionObject



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

def version
  say "Bookmaker version #{Bookmaker::VERSION}"
end