class Focus::Parser

Constants

DEFAULT_VALUES

Public Class Methods

parse(options) click to toggle source
# File lib/focus/cli.rb, line 13
def parse(options)
  args = OpenStruct.new(DEFAULT_VALUES)
  parser = build_parser(args)
  parser.parse!(options)
  args
end

Private Class Methods

build_parser(args) click to toggle source
# File lib/focus/cli.rb, line 22
def build_parser(args) # rubocop:disable MethodLength
  OptionParser.new do |opts|
    opts.banner = "Usage: focus [options]"

    opts.on("-v", "--verbose", "Run focus with more verbose STDOUT") do
      args.quiet = false
    end

    opts.on("-d", "--daemonize", "Allow focus to be forked to the background") do
      args.daemonize = true
    end

    opts.on("-t", "--target=TARGET", "Specify what you are focusing on") do |t|
      raise ArgumentError, "#{t} is not a valid target name" if t =~ /^\d+(\.\d)?$/
      args.target = t
    end

    opts.on("-mMINUTES", "--minutes=MINUTES", "How many minutes to focus.") do |m|
      args.minutes = m
    end

    opts.on("-h", "--help", "Prints this help") do
      puts opts
      exit
    end
  end
end