class FeedTheZettelkasten::CLI::Options

Parse CLI options

Constants

DEFAULTS

Attributes

args[R]

Public Class Methods

new(args) click to toggle source
# File lib/feed_the_zettelkasten/cli/options.rb, line 17
def initialize(args)
  @args = args
end

Public Instance Methods

[](key) click to toggle source
# File lib/feed_the_zettelkasten/cli/options.rb, line 21
def [](key)
  parse[key]
end
to_hash() click to toggle source
# File lib/feed_the_zettelkasten/cli/options.rb, line 25
def to_hash
  parse
end

Private Instance Methods

option_parser() click to toggle source
# File lib/feed_the_zettelkasten/cli/options.rb, line 54
def option_parser
  OptionParser.new do |opts|
    opts.banner = 'Usage: feed-the-zettelkasten [options] NOTES_DIR'
    opts.on('--from[=DATE]', Date, 'Include notes after DATE (default: 30 days ago)')
    opts.on('--to[=DATE]', Date, 'Include notes before DATE (default: today)')
    opts.on('--target[=INTEGER]', Integer, 'Number of notes required to meet daily goal (default: 3)')
    opts.on('--ext[=STRING]', 'Note extension (default: md)')
    opts.on('-v', '--version', 'Print version') { exit 0 }
    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      exit 1
    end
  end
end
parse() click to toggle source
# File lib/feed_the_zettelkasten/cli/options.rb, line 33
def parse
  @parse ||= parse!
end
parse!() click to toggle source
# File lib/feed_the_zettelkasten/cli/options.rb, line 37
def parse!
  options = DEFAULTS.dup
  option_parser.parse!(args, into: options)
  options[:path] = args.shift

  unless options[:path]
    raise OptionParser::MissingArgument, 'Missing NOTES_DIR argument'
  end

  unless File.directory?(options[:path])
    raise OptionParser::InvalidArgument,
      "'#{ options[:path] } is not a directory"
  end

  options
end