Class: Klipbook::CLI

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/klipbook/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = Klipbook::Config.new) ⇒ CLI

Returns a new instance of CLI.



7
8
9
# File 'lib/klipbook/cli.rb', line 7

def initialize(config=Klipbook::Config.new)
  @config = config.read
end

Instance Method Details

#execute!Object



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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/klipbook/cli.rb', line 11

def execute!
  program :name, 'Klipbook'
  program :version, Klipbook::VERSION
  program :description, "Klipbook exports the clippings you've saved on your Kindle into JSON, Markdown, or pretty HTML"

  program :help, 'Source', "You must specify either `--from-file` or `--from-site` as an input."
  program :help, 'Config', "Note that command options can be stored in a file called ~/.klipbookrc. This file is YAML formatted and options should be snake case e.g.\n\n" +
    ":from_site: [email protected]:my-kindle-password\n" +
    ":output_dir: ~/my/default/output/directory\n"

  default_command :help

  command :list do |c|
    c.syntax = "klipbook list"
    c.description = "List the books on the site or in the clippings file"

    c.option '--from-file FILE', String, "Input clippings file"
    c.option '--from-site username:password', String, "Credentials for Kindle highlights site"
    c.option '-c', '--count COUNT', Integer, "Maximum number of books to list (default is #{Config::DEFAULT_MAXBOOKS})"

    c.action do |_args, options|
      merge_config(options, @config)

      Klipbook::Commands::List.new.run!(options)
    end
  end

  command :export do |c|
    c.syntax = 'klipbook export'
    c.description = 'Export book clippings'

    c.option '--from-file FILE', String, "Input clippings file"
    c.option '--from-site username:password', String, "Credentials for Kindle highlights site"
    c.option '-c', '--count COUNT', Integer, "Maximum number of books to list (default is #{Config::DEFAULT_MAXBOOKS})"
    c.option '--format FORMAT', "Format to export in [html, markdown, or json]"
    c.option '--output-dir DIRECTORY', "Directory to export files to (default pwd)"
    c.option '-f', '--force', "Force overwrite of existing files"

    c.action do |_args, options|
      merge_config(options, @config)

      Klipbook::Commands::Export.new.run!(options)
    end
  end

  run!
end