Class: Daisy::CLI

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

Overview

Command line interpreter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_name) ⇒ CLI

Creates the interpreter for a command named command_name.



21
22
23
# File 'lib/daisy/cli.rb', line 21

def initialize(command_name)
  @command_name = command_name
end

Instance Attribute Details

#command_nameObject (readonly)

name of the command



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

def command_name
  @command_name
end

#re_encodeObject (readonly)

re-encode option



12
13
14
# File 'lib/daisy/cli.rb', line 12

def re_encode
  @re_encode
end

#source_dirObject (readonly)

source directory



15
16
17
# File 'lib/daisy/cli.rb', line 15

def source_dir
  @source_dir
end

#target_dirObject (readonly)

target directory



18
19
20
# File 'lib/daisy/cli.rb', line 18

def target_dir
  @target_dir
end

Instance Method Details

#runObject

Runs the interpreter.



26
27
28
29
30
31
32
33
34
35
# File 'lib/daisy/cli.rb', line 26

def run
  parse_arguments
  begin
    book = Book.new(source_dir, target_dir, re_encode: re_encode)
    book.create_daisy
  rescue Error => ex
    warn ex.message
    exit
  end
end

#usageObject

Displays the command usage and exits.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/daisy/cli.rb', line 38

def usage
  puts <<~EOT.lines.map { |t| "  #{t}" }

    #{command_name} [OPTIONS] [SOURCE] [TARGET]

    OPTIONS
    -h, --help        display this text and exit
    -e, --re-encode   re-encode mp3 files with lame
    --                end of options

    SOURCE  source directory, '.' by default
    TARGET  target directory, 'SOURCE/daisy' by default

    The source directory or one of its parents must contain a "daisy.yaml" or "daisy.yml" file.
    In this file, the first 2 keys are required:
    ---
    title: book title
    creator: book author
    narrator: narrator name
    language: ISO code like "fr", "fr-CA", "en", etc.
    publisher: ...
    rights: license terms or rights owner
    source publisher: ...
    source edition: ...
  EOT
  exit
end