Class: Daisy::CLI
- Inherits:
-
Object
- Object
- Daisy::CLI
- Defined in:
- lib/daisy/cli.rb
Overview
Command line interpreter.
Instance Attribute Summary collapse
-
#command_name ⇒ Object
readonly
name of the command.
-
#re_encode ⇒ Object
readonly
re-encode option.
-
#source_dir ⇒ Object
readonly
source directory.
-
#target_dir ⇒ Object
readonly
target directory.
Instance Method Summary collapse
-
#initialize(command_name) ⇒ CLI
constructor
Creates the interpreter for a command named
command_name
. -
#run ⇒ Object
Runs the interpreter.
-
#usage ⇒ Object
Displays the command usage and exits.
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_name ⇒ Object (readonly)
name of the command
9 10 11 |
# File 'lib/daisy/cli.rb', line 9 def command_name @command_name end |
#re_encode ⇒ Object (readonly)
re-encode option
12 13 14 |
# File 'lib/daisy/cli.rb', line 12 def re_encode @re_encode end |
#source_dir ⇒ Object (readonly)
source directory
15 16 17 |
# File 'lib/daisy/cli.rb', line 15 def source_dir @source_dir end |
#target_dir ⇒ Object (readonly)
target directory
18 19 20 |
# File 'lib/daisy/cli.rb', line 18 def target_dir @target_dir end |
Instance Method Details
#run ⇒ Object
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. exit end end |
#usage ⇒ Object
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 |