lib/furichan/cli.rb in furichan-0.1.2 vs lib/furichan/cli.rb in furichan-0.1.3

- old
+ new

@@ -1,73 +1,32 @@ -# coding: utf-8 - require 'thor' -require 'date' -require 'active_support/time' -require 'furik/cli' +require "furichan/furichan_util" module Furichan class CLI < Thor + include FurichanUtil + default_command :furichan - desc 'furichan', 'Do the all of week task' + desc 'furichan', "Create file and write about this week's reflection" def furichan invoke :init - invoke :furik + invoke :reflection end desc 'init', 'initialize of week setting' def init - wmonth = Time.now().strftime('%Y-%m-') + week_of_month - `git checkout -b #{wmonth}` - `mkdir -p #{wmonth}` - `cp template.md #{wmonth}/README.md` + #init_branch + init_file end - desc 'furik', 'this week"s furik' - def furik - wmonth = Time.now().strftime('%Y-%m-') + week_of_month - dest = Pathname(wmonth + '/README.md') - dest.open('w') { |f| f.puts furik_init } + desc 'reflection', "write file about this week's furik" + def reflection + set_template(create_template) end - private - - def week_of_month - today = Date.today() - beginning_of_month = today.beginning_of_month - cweek = today.cweek - beginning_of_month.cweek - - # It should be first week. - # Don't add when begining of month is saturday or sunday - # ex 2017/07/07(Fri) -> 1 - unless beginning_of_month.saturday? or beginning_of_month.sunday? - cweek += 1 - end - - cweek.to_s - end - - def furik_init - week = Date.today.beginning_of_week - furik = Furik::Cli.new - furik.options = { - gh: true, - ghe: true, - from: week.to_s, - to: week.end_of_week.to_s, - since: 0, - } - activity = capture_stdout { furik.activity } - activity.gsub!('7days Activities', '## 7days Activity') - end - - def capture_stdout - out = StringIO.new - $stdout = out - yield - return out.string - ensure - $stdout = STDOUT + desc 'furik', "write stdout this week's furik" + def furik + init_furik end end end