waddup 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 124b07086882a87d52aeac3f2774ef9189eb9c6c
4
- data.tar.gz: a760abd321c924beca39c80bb54dbd190277b7ac
3
+ metadata.gz: 41d84aaf796c2b8557e948350c43c4e451833217
4
+ data.tar.gz: 3acf2d4a01290ffbbec9382bdc42294226df4738
5
5
  SHA512:
6
- metadata.gz: c56e90b616d1d99204b4e9a09f138d925522fa8fed652b4d4a9aa6c0b2f2825ef35b57251c8cd152a7d8fe2a1d08bb344643b70e22cebaa66c30d788b176f838
7
- data.tar.gz: 2dbe261c3af49768d231a8e30c258c44743067f8efecf54b9f4ec3f52fd560d3260bb03d12572ceae4138ca4883f333eb69341d23e9fd9930bd1facd9c9a9108
6
+ metadata.gz: e4555eb4f6aa5572113ad4e24064140b59af2d9442e6a48dcb9e9d555105d8fd6ca5304c936f447e461f12f6517b01060911dd38cf0b038f623cbc20a005f2c8
7
+ data.tar.gz: 109ba65acf536fe8324fb4af8bd498b732a0d098212e7391ac3bd45aaa3c80981d243d9810154a4850568121dcb701501ada8fc69d08996e99fdf4f94ca6a6dd
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.2.0 - November 29, 2013
4
+ - Proper CLI implementation supporting `--version` and `--help`.
5
+ - Visual and JSON output support using `--format`.
6
+
3
7
  ### v0.1.0 - November 29, 2013
4
8
  - Drop support for 1.8.7 and 1.9.2.
5
9
  - From/to arguments are treated as past by default.
data/README.md CHANGED
@@ -81,3 +81,12 @@ To specify an end date, use one of `to`, `until`, `uptil`, `upto` or `through`:
81
81
  waddup through yesterday
82
82
 
83
83
  Defaults to right now if an end date is ommitted.
84
+
85
+
86
+ ### Formats
87
+
88
+ At present, Waddup supports two formats: visual (see screenshot) and JSON.
89
+
90
+ Use the `--format` flag to indicate the desired output format:
91
+
92
+ waddup since yesterday --format json
data/bin/sup CHANGED
@@ -1,6 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'waddup'
4
3
  require 'waddup/cli'
5
-
6
- Waddup::CLI.new.run! ARGV
data/bin/waddup CHANGED
@@ -1,6 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'waddup'
4
3
  require 'waddup/cli'
5
-
6
- Waddup::CLI.new.run! ARGV
@@ -8,4 +8,4 @@ require 'waddup/source'
8
8
  require 'waddup/sources/apple_calendar'
9
9
  require 'waddup/sources/apple_mail'
10
10
  require 'waddup/sources/git'
11
- require 'waddup/version'
11
+ require 'waddup/metadata'
@@ -1,10 +1,15 @@
1
1
  require 'chronic'
2
2
 
3
+ require 'waddup'
4
+
3
5
  module Waddup
4
6
 
5
7
  class CLI
8
+ require 'commander/import'
6
9
 
7
- attr_accessor :sources, :from, :to
10
+ program :name, Waddup::NAME
11
+ program :version, Waddup::VERSION
12
+ program :description, Waddup::SUMMARY
8
13
 
9
14
  KEYWORDS = {
10
15
  sources: %w[with],
@@ -14,61 +19,83 @@ module Waddup
14
19
 
15
20
  KEYWORD_BOUNDARY = "(?:\\s#{KEYWORDS.values.flatten.join('|\\s')}|\\Z)"
16
21
 
17
- def parse!
18
- parse_keyword :sources do |match|
19
- sources = match[1]
20
- @sources = Waddup::Source.usable.select do |source|
21
- sources.include? source::ALIAS
22
+ class << self
23
+
24
+ attr_accessor :sources, :from, :to
25
+
26
+ def parse!(arguments)
27
+ @arguments = arguments.join ' '
28
+
29
+ parse_keyword :sources do |match|
30
+ sources = match[1]
31
+ @sources = Waddup::Source.usable.select do |source|
32
+ sources.include? source::ALIAS
33
+ end
34
+ end
35
+
36
+ parse_keyword :from do |match|
37
+ @from = Chronic.parse match[1], context: :past
22
38
  end
23
- end
24
39
 
25
- parse_keyword :from do |match|
26
- @from = Chronic.parse match[1], context: :past
40
+ parse_keyword :to do |match|
41
+ @to = Chronic.parse match[1], context: :past
42
+ end
27
43
  end
28
44
 
29
- parse_keyword :to do |match|
30
- @to = Chronic.parse match[1], context: :past
45
+ def parse_keyword(keyword, &block)
46
+ @arguments.match /(?:#{KEYWORDS[keyword].join('|')})\s(.+?)#{KEYWORD_BOUNDARY}/i, &block
31
47
  end
32
- end
33
48
 
34
- def parse_keyword(keyword, &block)
35
- @arguments.match /(?:#{KEYWORDS[keyword].join('|')})\s(.+?)#{KEYWORD_BOUNDARY}/i, &block
36
49
  end
37
50
 
38
- # Parses given arguments, aggregates events and renders timesheet
39
- def run!(arguments)
40
- @arguments = arguments.join ' '
41
-
42
- parse!
51
+ default_command :timesheet
43
52
 
44
- # Sanity checking
45
- @sources ||= Waddup::Source.usable
46
- @from ||= Time.now
47
- @to ||= Time.now
48
-
49
- # Aggregate events from all sources
50
- events = sources.map do |source|
51
- source.new.events from, to
52
- end
53
+ command :timesheet do |c|
54
+ c.syntax = 'waddup with git and mail since last monday 9:00 until yesterday morning'
55
+ c.description = 'Aggregates events and generates timesheet between from and to range'
56
+ c.option '--format visual | json', String, 'Provides timesheet in specified format'
57
+ c.action do |args, options|
58
+ parse! args
53
59
 
54
- # Sort events
55
- events.flatten!
56
- events.sort_by! &:at
60
+ # Sanity checking
61
+ @sources ||= Waddup::Source.usable
62
+ @from ||= Time.now
63
+ @to ||= Time.now
57
64
 
58
- # Group daily
59
- days = events.group_by { |event| event.at.to_date }
65
+ # Aggregate events from all sources
66
+ events = sources.map do |source|
67
+ source.new.events from, to
68
+ end
60
69
 
61
- # Generate timesheet
62
- days.each_pair do |day, events|
63
- puts
64
- puts day.strftime('%A, %-d %B %Y')
65
- puts
66
- events.each do |event|
67
- puts " #{event.at.strftime('%H:%M')} #{event.source.class::ICON} #{event.label}"
70
+ # Sort events
71
+ events.flatten!
72
+ events.sort_by! &:at
73
+
74
+ # Group daily
75
+ days = events.group_by { |event| event.at.to_date }
76
+
77
+ # Generate timesheet in requested format
78
+ case options.format
79
+ when 'json'
80
+ require 'json'
81
+ puts JSON.generate days
82
+ when 'visual'
83
+ days.each_pair do |day, events|
84
+ puts
85
+ puts day.strftime('%A, %-d %B %Y')
86
+ puts
87
+
88
+ events.each do |event|
89
+ puts " #{event.at.strftime('%H:%M')} #{event.source.class::ICON} #{event.label}"
90
+ end
91
+ end
92
+
93
+ puts
94
+ else
95
+ raise 'Format needs to be either visual or json'
68
96
  end
69
- end
70
97
 
71
- puts
98
+ end
72
99
  end
73
100
 
74
101
  end
@@ -9,6 +9,15 @@ module Waddup
9
9
  yield self if block_given?
10
10
  end
11
11
 
12
+ def to_json(state)
13
+ {
14
+ :label => label,
15
+ :at => at,
16
+ :until => @until,
17
+ :source => source.class::ALIAS
18
+ }.to_json
19
+ end
20
+
12
21
  end
13
22
 
14
23
  end
@@ -0,0 +1,7 @@
1
+ module Waddup
2
+
3
+ NAME = 'Waddup'
4
+ VERSION = '0.2.0'
5
+ SUMMARY = 'Waddup retraces your activities from arbitrary sources such as version control, issue tracking software and mail clients'
6
+
7
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  $:.push File.expand_path('../lib', __FILE__)
4
4
 
5
- require 'waddup/version'
5
+ require 'waddup/metadata'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = 'waddup'
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
10
10
  s.authors = ['Tim Kurvers']
11
11
  s.email = ['tim@moonsphere.net']
12
12
  s.homepage = 'https://github.com/timkurvers/waddup'
13
- s.summary = 'Waddup retraces your activities from arbitrary sources such as version control, issue tracking software and mail clients'
14
- s.description = 'Waddup retraces your activities from arbitrary sources - such as version control, issue tracking software and mail clients - and displays them in a neat chronological overview'
13
+ s.summary = Waddup::SUMMARY
14
+ s.description = "#{Waddup::SUMMARY} - and displays them in a neat chronological overview"
15
15
 
16
16
  s.rubyforge_project = 'waddup'
17
17
 
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ['lib']
22
22
 
23
- s.add_dependency 'chronic', '~> 0.10.2'
23
+ s.add_dependency 'chronic', '~> 0.10.2'
24
+ s.add_dependency 'commander', '~> 4.1.5'
24
25
 
25
26
  s.add_development_dependency 'rake'
26
27
  s.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waddup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Kurvers
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.10.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: commander
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.1.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.1.5
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +136,7 @@ dependencies:
122
136
  - - '>='
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
- description: Waddup retraces your activities from arbitrary sources - such as version
139
+ description: Waddup retraces your activities from arbitrary sources such as version
126
140
  control, issue tracking software and mail clients - and displays them in a neat
127
141
  chronological overview
128
142
  email:
@@ -151,6 +165,7 @@ files:
151
165
  - lib/waddup/extensions/applescript.rb
152
166
  - lib/waddup/extensions/file_system.rb
153
167
  - lib/waddup/extensions/system.rb
168
+ - lib/waddup/metadata.rb
154
169
  - lib/waddup/registry.rb
155
170
  - lib/waddup/source.rb
156
171
  - lib/waddup/sources/apple_calendar.rb
@@ -158,7 +173,6 @@ files:
158
173
  - lib/waddup/sources/apple_mail.rb
159
174
  - lib/waddup/sources/apple_mail/sent_mail.applescript
160
175
  - lib/waddup/sources/git.rb
161
- - lib/waddup/version.rb
162
176
  - spec/fixtures/sources/apple_calendar.results
163
177
  - spec/fixtures/sources/apple_mail.results
164
178
  - spec/fixtures/sources/git.log
@@ -1,5 +0,0 @@
1
- module Waddup
2
-
3
- VERSION = '0.1.0'
4
-
5
- end