Class: Herodot::Application

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/herodot.rb

Constant Summary collapse

USER_HOME =
File.expand_path('~').to_s
INIT_DESCRIPTION =
'This command sets up post commit and post checkout hooks'\
', that will log the current branch into the worklog file.'.freeze
TRACK_DESCRIPTION =
'This command tracks the current branch/commit in a repo '\
'and is called from the git hooks installed via `herodot init`.'.freeze
SHOW_DESCRIPTION =
'This command parses the worklog file and returns the'\
'git branch based worklog according to the'\
'work times specified in the `~/.herodot.yml`.'.freeze
'This command can link a repository to a project issue tracking tool.'\
' The commmands writes the settings in `project_path/.herodot.yml`.'.freeze

Instance Method Summary collapse

Instance Method Details

#init_command(config) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/herodot.rb', line 32

def init_command(config)
  command :init do |c|
    c.syntax = 'herodot init [<repository path>]'
    c.summary = 'Start tracking a repository'
    c.description = INIT_DESCRIPTION
    c.example 'Start tracking current repository', 'herodot init'
    c.action do |args, _|
      Commands.init(args[0], config)
    end
  end
end


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/herodot.rb', line 76

def link_command(_)
  command :link do |c|
    c.syntax = 'herodot link [<repository path>]'
    c.summary = 'Link project with issue tracker'
    c.description = SHOW_DESCRIPTION
    c.example 'Link current repository', 'herodot link'
    c.action do |args, _|
      Commands.link(args[0])
    end
  end
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/herodot.rb', line 16

def run
  program :name, 'herodot'
  program :version, VERSION
  program :description, 'Tracks your work based on git branch checkouts'

  config = Configuration.new
  init_command(config)
  track_command(config)
  show_command(config)
  link_command(config)
  default_command :show
  run!
end

#show_command(config) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/herodot.rb', line 61

def show_command(config)
  command :show do |c|
    c.syntax = 'herodot show [<time range>]'
    c.summary = 'Shows worklogs'
    c.description = SHOW_DESCRIPTION
    c.option '--format FORMAT', String, 'Uses specific output format (Supported: json)'
    show_command_examples(c)
    c.action do |args, options|
      Commands.show(args, config, options)
    end
  end
end

#show_command_examples(c) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/herodot.rb', line 88

def show_command_examples(c)
  c.example 'Shows this weeks worklogs', 'herodot show'
  c.example 'Shows last weeks worklogs', 'herodot show last week'
  c.example 'Shows worklogs for last monday', 'herodot show monday'
  c.example 'Shows worklogs for 12-12-2016', 'herodot show 12-12-2016'
  c.example 'Shows last weeks worklogs as json', 'herodot show --format json last week'
  c.example 'Shows last weeks worklogs as json (short)', 'herodot show -f json last week'
end

#track_command(config) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/herodot.rb', line 46

def track_command(config)
  command :track do |c|
    c.syntax = 'herodot track <repository path>'
    c.summary = 'Record git activity in a repository (used internally)'
    c.description = TRACK_DESCRIPTION
    c.example 'Record the latest branch name etc. to the worklog', 'herodot track .'
    c.action do |args, _|
      Commands.track(args[0], config)
    end
  end
end