bin/klipbook in klipbook-1.0.2 vs bin/klipbook in klipbook-2.0.0
- old
+ new
@@ -23,36 +23,56 @@
desc 'Number of books to process'
arg_name 'count'
default_value 1
flag [:n, :'num-books']
-desc 'Collate your clippings into a html file for each book'
+desc 'Collate your clippings into a single json file'
arg_name 'source'
-long_desc "Clippings are fetched from the specified source before being collated into html " +
- "files and written into the current directory.\n\n" + SOURCE_HELP
+long_desc "Clippings are fetched from the specified source, collated, and written into a single json file.\n\n" +
+ SOURCE_HELP
command :collate do |c|
- c.desc 'Override the directory path where collated files are written'
+ c.desc 'Specify the name of the json file to be written to.'
+ c.arg_name 'File-name'
+ c.flag [:c, :'output-file']
+
+ c.desc 'Force overwrite of any existing book entries within the output file'
+ c.switch [:f, :force]
+
+ c.action do |globals,options,args|
+ book_file_path = output_file(options)
+ books = fetch_books(args, globals)
+ Klipbook::Commands::Collate.new(books, book_file(book_file_path)).call(book_file_path, options[:f])
+ end
+end
+
+desc 'Pretty print your clippings into a html file for each book'
+arg_name 'source'
+long_desc "Clippings are fetched from the specified source before being written to html " +
+ "files in the output directory.\n\n" + SOURCE_HELP
+command :pprint do |c|
+
+ c.desc 'Override the directory path where html files are written'
c.arg_name 'Directory'
c.flag [:o, :'output-dir']
- c.desc 'Force overwrite of any existing collated files'
+ c.desc 'Force overwrite of any existing files'
c.switch [:f, :force]
c.action do |globals,options,args|
books = fetch_books(args, globals)
- Klipbook::Collator.new(books).collate_books(output_dir(options), options[:f])
+ Klipbook::Commands::PrettyPrint.new(books).call(output_dir(options), options[:f])
end
end
desc 'List available books'
arg_name 'source'
-long_desc "Clippings are fetched from the specified source before being listed to screen.\n\n" + SOURCE_HELP
+long_desc "List the books from the specified source to screen.\n\n" + SOURCE_HELP
command :list do |c|
c.action do |globals,options,args|
books = fetch_books(args, globals)
- Klipbook::Printer.new(books).print
+ Klipbook::Commands::ListBooks.new(books).call
end
end
pre do |globals,command,options,args|
unless source_spec(args)
@@ -73,19 +93,35 @@
on_error do |exception|
true
end
+def book_file(file_path)
+ raw_json = if File.exist?(file_path)
+ File.open(file_path, 'r') do |f|
+ f.read
+ end
+ else
+ ''
+ end
+
+ Klipbook::Collate::BookFile.from_json(raw_json)
+end
+
def source_spec(args)
@source_spec ||= (args[0] || Klipbook::Config.new.read[:source])
end
def fetch_books(args, globals)
- Klipbook::Fetcher.new(source_spec(args), globals[:n].to_i).fetch_books
+ Klipbook::Sources::BookSource.new(source_spec(args), globals[:n].to_i).books
end
def output_dir(options)
@output_dir ||= (options[:o] || Klipbook::Config.new.read[:output] || Dir.pwd)
+end
+
+def output_file(options)
+ @output_file ||= (options[:c] || Klipbook::Config.new.read[:output_file] || File.join(Dir.pwd, 'books.json'))
end
exit run(ARGV)