Sha256: d843c68a5d00909365cc7df06d98074dbec404525aa99693872d5ce3cdad09ba

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'git'
require 'logger'
require 'wakatime'
require 'chronic_duration'
require 'yaml'
require 'thor'
require 'active_support/core_ext/date/calculations'
require 'active_support/core_ext/date_and_time/calculations'
require 'active_support/core_ext/integer/time'
require 'active_support/core_ext/time'

module  GitWakaTime
  # Provides two CLI actions init and tally
  class Cli < Thor
    include Thor::Actions
    desc 'init', 'Setups up Project for using the wakatime API
      it will also add to your git ignore file'
    method_option :file, aliases: '-f', default: '.'

    def init
      say('Adding .wakatime.yml to home directory')

      create_file File.join(Dir.home, '.wakatime.yml') do
        YAML.dump(api_key: 'Your API Key', last_commit: nil, log_level: :info)
      end
    end

    desc 'tally', 'Produce time spend for each commit and file in each commit'
    method_option :file, aliases: '-f', default: '.'
    method_option :start_on, aliases: '-s', default: nil
    def tally
      path, GitWakaTime.config.root = File.expand_path(options.file)
      date = Date.parse(options.start_on) if options.start_on
      date = 1.month.ago.beginning_of_month unless options.start_on
      GitWakaTime.config.load_config_yaml
      @git_map = Mapper.new(path, start_at: date)
      @actions = Query.new(@git_map.commits, File.basename(path)).get

      @timer   = Timer.new(@git_map.commits, @actions, File.basename(path)).process

      @timer.each do |date, commits|
        Log.new format('%-40s %-40s'.blue,
                       date,
                       "Total #{ChronicDuration.output commits.map(&:time_in_seconds).reduce(&:+)}"
                       )
        commits.each do |commit|
          # Log.new commit.message
          Log.new commit.to_s
          commit.files.each { |file| Log.new file.to_s }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitwakatime-0.0.2 lib/gitwakatime/cli.rb