class Herodot::Commands

Constants

DEFAULT_RANGE
SCRIPT

Public Class Methods

init(path, config) click to toggle source
# File lib/herodot/commands.rb, line 21
def self.init(path, config)
  path = '.' if path.nil?
  puts "Start tracking of `#{File.expand_path(path)}` into `#{config.worklog_file}`."
  hooks = "#{path}/.git/hooks"
  abort('Path is not a git repository.') unless File.exist?(hooks)
  %w[post-checkout post-commit].each do |name|
    File.open("#{hooks}/#{name}", 'w') { |file| file.write(SCRIPT) }
    File.chmod(0o755, "#{hooks}/#{name}")
    FileUtils.touch(config.worklog_file)
  end
end
show(args, config, opts = {}) click to toggle source
# File lib/herodot/commands.rb, line 11
def self.show(args, config, opts = {})
  subject = args.empty? ? DEFAULT_RANGE : args.join(' ')
  range = Chronic.parse(subject, guess: false, context: :past)
  abort "Date not parsable: #{args.join(' ')}" unless range
  worklog = Parser.parse(range, config)
  decorated_worklog = ProjectLink.new(worklog)
  output = Output.print(decorated_worklog.totals, opts)
  puts output
end
track(path, config) click to toggle source
# File lib/herodot/commands.rb, line 33
def self.track(path, config)
  puts 'Logging into worklog'
  File.open(config.worklog_file, 'a') do |worklog|
    datestr = Time.now.strftime('%a %b %e %H:%M:%S %z %Y')
    branch = `(cd #{path} && git rev-parse --abbrev-ref HEAD)`.strip
    line = [datestr, path, branch].join(';')
    worklog.puts(line)
  end
end