Class: Verku::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/verku/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/verku/cli.rb', line 12

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: verku help new"
  end
  super
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)

9
10
11
# File 'lib/verku/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/verku/cli.rb', line 21

def create(path)
  say "Verku -- 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/verku/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
  Verku::Exporter.run(root_dir, options)
end

#move(oid, nid) ⇒ Object


68
69
70
71
# File 'lib/verku/cli.rb', line 68

def move(oid,nid)
  s = Structure.new(root_dir)
  s.move(oid,nid)
end

#pdfObject


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

def pdf
  inside_ebook!
  Verku::Exporter.run(root_dir, {:only => 'pdf'})
end

#statsObject


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/verku/cli.rb', line 53

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

  say [
    # "Chapters: #{stats.chapters}",
    "Goal:     #{sprintf("%7d", stats.target)}",
    "Words:    #{sprintf("%7d", stats.words)}",
    "          -------",
    "Remain:   #{sprintf("%7d", stats.remaining)}",
    "Progress: #{sprintf("%7d", stats.today)}"
  ].join("\n")
end

#trash(scene_id) ⇒ Object


73
74
75
76
# File 'lib/verku/cli.rb', line 73

def trash(scene_id)
  s = Structure.new(root_dir)
  s.trash(scene_id)
end

#versionObject


48
49
50
# File 'lib/verku/cli.rb', line 48

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