lib/controllers/generate.rb in evertils-0.1.4 vs lib/controllers/generate.rb in evertils-0.1.5

- old
+ new

@@ -1,8 +1,10 @@ module Granify module Controller class Generate < Controller::Base + attr_accessor :force + def pre_exec begin # interface with the Evernote API so we can use it later @model = Granify::Helper.load('evernote') @@ -15,38 +17,53 @@ Notify.error("Evernote.authenticate error\n#{e.message} (#{e.errorCode})") rescue ::Evernote::EDAM::Error::EDAMUserException => e Notify.error("Evernote.authenticate error\n#{e.parameter} (#{e.errorCode})") end + OptionParser.new do |opt| + opt.banner = "#{Granify::PACKAGE_NAME} generate timeframe [...-flags]" + + opt.on("-f", "--force", "Force execution") do + @force = true + end + end.parse! + super end # generate daily notes def daily - if @model.note_exists - Notify.error("There's already a log for today!") + if !@force + if @model.note_exists + Notify.error("There's already a log for today!") + end end @model.create_note end # generate weekly notes def weekly - if @model.note_exists - Notify.error("There's already a log for this week!") - end + if !@force + if @model.note_exists + Notify.error("There's already a log for this week!") + end - if !Date.today.monday? - Notify.error("Sorry, you can only create new weekly logs on Mondays") + + if !Date.today.monday? + Notify.error("Sorry, you can only create new weekly logs on Mondays") + end end @model.create_note end # generate monthly notes def monthly - if @model.note_exists - Notify.error("There's already a log for this month!") + if !@force + if @model.note_exists + Notify.error("There's already a log for this month!") + end end @model.create_note end end \ No newline at end of file