Class: Tcelfer::CLI::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/tcelfer/cli.rb

Overview

Thor CLI for Tcelfer

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ Base

Returns a new instance of Base.



30
31
32
33
34
35
# File 'lib/tcelfer/cli.rb', line 30

def initialize(*_args)
  # Quit on Ctrl-C please
  @prompt = TTY::Prompt.new(interrupt: :exit)

  super
end

Class Method Details

.exit_on_failure?Boolean

Useful return codes are nice, of course

Returns:

  • (Boolean)


38
39
40
# File 'lib/tcelfer/cli.rb', line 38

def self.exit_on_failure?
  true
end

Instance Method Details

#dayObject



55
56
57
58
59
60
61
62
# File 'lib/tcelfer/cli.rb', line 55

def day
  Tcelfer.config.debug = options[:verbose]
  store = Tcelfer::Storage.new
  tc_day = rec_day! store
  @prompt.say("Recorded [#{tc_day.date}]: #{Paint[tc_day.rating, :bold]}")
rescue Tcelfer::Error => e
  @prompt.error("[#{e.class}]", e)
end

#reportObject



67
68
69
70
71
72
73
# File 'lib/tcelfer/cli.rb', line 67

def report
  Tcelfer.config.debug = options[:verbose]
  rep = Report.new
  @prompt.say(gen_report(rep, options['month'], options['year'], options['legend']))
rescue Tcelfer::Error => e
  @prompt.error("[#{e.class}]", e)
end

#versionObject



48
49
50
# File 'lib/tcelfer/cli.rb', line 48

def version
  puts Tcelfer::VERSION
end

#ytdObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/tcelfer/cli.rb', line 76

def ytd
  Tcelfer.config.debug = options[:verbose]
  rep = Report.new
  1.upto(Date.today.mon) do |mon|
    @prompt.say(rep.generate_month_report(mon))
  end
  @prompt.say(Report.legend)
rescue Tcelfer::Error => e
  @prompt.error("[#{e.class}]", e)
end