Class: KoboNotesBinder::Cli
- Inherits:
-
Object
- Object
- KoboNotesBinder::Cli
- Defined in:
- lib/kobo_notes_binder/cli.rb
Instance Method Summary collapse
Instance Method Details
#parse(argv, defaults) ⇒ Object
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 65 66 67 |
# File 'lib/kobo_notes_binder/cli.rb', line 40 def parse(argv, defaults) = {}.merge defaults OptionParser.new do |opts| opts. = "Usage: kobo_notes_binder [options]" opts.on("-kPATH", "--kobo=PATH", "Path to kobo device. Default: #{[:kobo_device_path]}") do |v| [:kobo_device_path] = v end opts.on("-oPATH", "--output=PATH", "Output folder. Default: #{[:output_folder]}") do |v| [:output_folder] = v end opts.on("-p", "--open", "Open file at the end") do |v| [:open] = v end opts.on("-aNAME", "--application=NAME", "Application name to open epub") do |v| [:application_name] = v end opts.on("-d", "--debug", "Enable debug mode") do |v| [:debug_mode] = v end opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| [:verbose] = v end end.parse!(argv) end |
#start(argv) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kobo_notes_binder/cli.rb', line 5 def start(argv) argv = argv.dup defaults = { kobo_device_path: '/Volumes/KOBOeReader', output_folder: '~/Desktop', # Dev data # tmp_dir: '/Users/anton/projects/kobo_notes_binder/tmp/tmp_dir', # local_kobo_db_path: '/Users/anton/projects/ank/tmp/tmp_dir/KoboReader.sqlite', # local_original_epub_path: '/Users/anton/projects/ank/tmp/tmp_dir/Nine Lies About Work_ A Freethinking Leader’s Guide to the Real World.kepub.epub', # volume_url: "file:///mnt/onboard/kepub/Nine Lies About Work_ A Freethinking Leader’s Guide to the Real World.kepub.epub" } = parse(argv, defaults) puts runner = KoboNotesBinder::Runner.new(, kobo_device_path: [:kobo_device_path]) tmp_epub_path = runner.execute puts 'Moving book to desktop' new_epub_path = File.([:output_folder]) + '/' + File.basename(tmp_epub_path) FileUtils.mv tmp_epub_path, new_epub_path if [:open] cmd_args = ['open'] if [:application_name] cmd_args += ['-a', [:application_name]] end puts 'Opening file' system *cmd_args, new_epub_path end end |