<commit_before>require 'yaml'
require 'rexml/document'
require 'net/http'
require 'net/https'

require 'rubygems'
require 'chronic'
require 'trollop'

require 'hcl/timesheet_resource'
require 'hcl/project'
require 'hcl/task'
require 'hcl/day_entry'

# Workaround for annoying SSL warning:
#  >> warning: peer certificate won't be verified in this SSL session
# http://www.5dollarwhitebox.org/drupal/node/64
class Net::HTTP
  alias_method :old_initialize, :initialize
  def initialize(*args)
    old_initialize(*args)
    @ssl_context = OpenSSL::SSL::SSLContext.new
    @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
end

class HCl
  VERSION = "0.1.0"
  SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings"

  class UnknownCommand < StandardError; end

  def self.conf_file= filename
    @@conf_file = filename
  end

  def self.command *args
    hcl = new(@@conf_file).process_args(*args).run
  end

  def run
    if @command
      if respond_to? @command
        send @command, *@args
      else
        raise UnknownCommand, "unrecognized command `#{@command}'"
      end
    else
      show
    end
  end

  def initialize conf_file
    config = YAML::load File.read(conf_file)
    TimesheetResource.configure config
    read_settings
  end

  def process_args *args
    Trollop::options(args) do
      version "HCl #{VERSION}"
      stop_on %w[ show tasks set unset note add rm start stop ]
      banner <<-EOM
HCl is a command-line client for manipulating Harvest time sheets.

Commands:
    hcl show [date]
    hcl tasks
    hcl start <task> [msg]
    hcl stop [msg]
    hcl note <msg>
    hcl add <task> <duration> [msg]
    hcl rm [entry_id]

Examples:
    $ hcl tasks
    $ hcl start 1234 this is my log message
    $ hcl show yesterday
    $ hcl show last tuesday

Options:
EOM
    end
    @command = args.shift
    @args = args
    self
  end

  def tasks
    Task.all.each do |task|
      # TODO more information and formatting options
      puts "#{task.project.id} #{task.id}\t#{task}"
    end
  end<commit_msg>Improve the usage example given by --help.<commit_after>require 'yaml'
require 'rexml/document'
require 'net/http'
require 'net/https'

require 'rubygems'
require 'chronic'
require 'trollop'

require 'hcl/timesheet_resource'
require 'hcl/project'
require 'hcl/task'
require 'hcl/day_entry'

# Workaround for annoying SSL warning:
#  >> warning: peer certificate won't be verified in this SSL session
# http://www.5dollarwhitebox.org/drupal/node/64
class Net::HTTP
  alias_method :old_initialize, :initialize
  def initialize(*args)
    old_initialize(*args)
    @ssl_context = OpenSSL::SSL::SSLContext.new
    @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
end

class HCl
  VERSION = "0.1.0"
  SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings"

  class UnknownCommand < StandardError; end

  def self.conf_file= filename
    @@conf_file = filename
  end

  def self.command *args
    hcl = new(@@conf_file).process_args(*args).run
  end

  def run
    if @command
      if respond_to? @command
        send @command, *@args
      else
        raise UnknownCommand, "unrecognized command `#{@command}'"
      end
    else
      show
    end
  end

  def initialize conf_file
    config = YAML::load File.read(conf_file)
    TimesheetResource.configure config
    read_settings
  end

  def process_args *args
    Trollop::options(args) do
      version "HCl #{VERSION}"
      stop_on %w[ show tasks set unset note add rm start stop ]
      banner <<-EOM
HCl is a command-line client for manipulating Harvest time sheets.

Commands:
    hcl show [date]
    hcl tasks
    hcl set <key> <value ...>
    hcl start <task> [msg]
    hcl stop [msg]
    hcl note <msg>
    hcl add <task> <duration> [msg]
    hcl rm [entry_id]

Examples:
    $ hcl tasks
    $ hcl start 1234 4567 this is my log message
    $ hcl set task.mytask 1234 4567
    $ hcl start mytask this is my next log message
    $ hcl show yesterday
    $ hcl show last tuesday

Options:
EOM
    end
    @command = args.shift
    @args = args
    self
  end

  def tasks
    Task.all.each do |task|
      # TODO more information and formatting options
      puts "#{task.project.id} #{task.id}\t#{task}"
    end
  end
{'fraction_non_alphanumeric': 0.09802990742938524, 'fraction_numerical': 0.0075955376216472826, 'mean_word_length': 3.0597302504816954, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6453832', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1387, 'n_words': 430}