fewald-worklog 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a96472b19aed7c8be5089c026c81feb764d2b48a2694fd77d7cbbe10cc116639
4
- data.tar.gz: 879af891f9009e3c0afe477d4cab68404970647e35a4d82cc8f30f2e3d54964d
3
+ metadata.gz: 58355177c4287e00546bceb657e475a665a6a0ee374d57e836f220c1e7e57762
4
+ data.tar.gz: a071e07481282a7e9d857a32ec7e7fe01d71aff05ed1ededf456a5bef253dca1
5
5
  SHA512:
6
- metadata.gz: 5a2e2329393e493c533cd092eda4ca1a3db201a36224d80a332eca08f0a1355c1aa61df608388c9d316410715aed7bfdc1b01298004a7a9f24d9fb440d49c69f
7
- data.tar.gz: a16ffafc2dafae3796d013f01ec860c1a5b79fd61c81569c1f15ead531632a055c3455d9720c2c295d1bad8cdc32cb6d311db6fec32ca0606517effa953db3ce
6
+ metadata.gz: d2b996725ae935188acdfff6c1e71c81ceae62afe2386259a5687e8726967003fad557b0ba8d71bb28d91a13f50138b67a8165643c7a0ce75c33cce4bf5a2cf0
7
+ data.tar.gz: 5c5bb1134e3eda63975de71857401d7ae1aae24e264e65be97cee2de9fcf75c0407405478e44afc4238bd4cf6c2aab6615204b7617a25967e32d9978b2382ff3
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.5
data/bin/wl CHANGED
@@ -8,7 +8,8 @@ if ENV['WL_PATH']
8
8
  # This is used during development to avoid having to rely on the order of the $PATH.
9
9
  puts "Loading worklog from #{ENV['WL_PATH']}. This should only be used during development."
10
10
  puts 'To use the installed worklog, unset the WL_PATH environment variable.'
11
- require_relative File.join(ENV['WL_PATH'], 'lib', 'cli')
11
+ $LOAD_PATH.unshift File.join(ENV['WL_PATH'], 'lib')
12
+ require 'cli'
12
13
  else
13
14
  require_relative '../lib/cli'
14
15
  end
data/lib/cli.rb CHANGED
@@ -16,7 +16,6 @@ require 'printer'
16
16
  require 'statistics'
17
17
  require 'storage'
18
18
  require 'string_helper'
19
- require 'summary'
20
19
  require 'version'
21
20
  require 'webserver'
22
21
 
@@ -104,9 +103,22 @@ class WorklogCLI < Thor
104
103
  end
105
104
 
106
105
  desc 'tags', 'Show all tags used in the work log'
107
- def tags
106
+ option :date, type: :string, default: DateTime.now.strftime('%Y-%m-%d'),
107
+ desc: <<~DESC
108
+ Show the work log for a specific date. If this option is provided, --from and --to and --days should not be used.
109
+ DESC
110
+ option :from, type: :string, desc: <<~EOF
111
+ Inclusive start date of the range. Takes precedence over --date, if defined.
112
+ EOF
113
+ option :to, type: :string, desc: <<~EOF
114
+ Inclusive end date of the range. Takes precedence over --date, if defined.
115
+ EOF
116
+ option :days, type: :numeric, desc: <<~EOF
117
+ Number of days to show starting from --date. Takes precedence over --from and --to if defined.
118
+ EOF
119
+ def tags(tag = nil)
108
120
  worklog = Worklog.new
109
- worklog.tags(options)
121
+ worklog.tags(tag, options)
110
122
  end
111
123
 
112
124
  desc 'server', 'Start the work log server'
data/lib/log_entry.rb CHANGED
@@ -31,7 +31,7 @@ class LogEntry
31
31
  end
32
32
 
33
33
  # Returns the message string with formatting without the time.
34
- # @param people Hash[String, Person] A hash of people with their handles as keys.
34
+ # @param known_people Hash[String, Person] A hash of people with their handles as keys.
35
35
  def message_string(known_people = nil)
36
36
  # replace all mentions of people with their names.
37
37
  msg = @message.dup
data/lib/worklog.rb CHANGED
@@ -14,6 +14,7 @@ require 'worklogger'
14
14
  require 'string_helper'
15
15
  require 'printer'
16
16
  require 'statistics'
17
+ require 'summary'
17
18
 
18
19
  # Main class providing all worklog functionality.
19
20
  # This class is the main entry point for the application.
@@ -138,9 +139,25 @@ class Worklog
138
139
  end
139
140
  end
140
141
 
141
- def tags(_options = {})
142
- all_logs = @storage.all_days
142
+ # Show all tags used in the work log or details for a specific tag
143
+ #
144
+ # @param tag [String, nil] the tag to show details for, or nil to show all tags
145
+ # @param options [Hash] the options hash containing date range
146
+ # @return [void]
147
+ #
148
+ # @example
149
+ # worklog.tags('example_tag', from: '2023-10-01', to: '2023-10-31')
150
+ # worklog.tags(nil) # Show all tags for all time
151
+ def tags(tag = nil, options = {})
152
+ if tag.nil? || tag.empty?
153
+ tag_overview
154
+ else
155
+ tag_detail(tag, options)
156
+ end
157
+ end
143
158
 
159
+ def tag_overview
160
+ all_logs = @storage.all_days
144
161
  puts Rainbow('Tags used in the work log:').gold
145
162
 
146
163
  # Count all tags used in the work log
@@ -153,6 +170,29 @@ class Worklog
153
170
  tags.sort.each { |k, v| puts "#{Rainbow(k.ljust(max_len)).gold}: #{v} #{pluralize(v, 'occurrence')}" }
154
171
  end
155
172
 
173
+ # Show detailed information about a specific tag
174
+ #
175
+ # @param tag [String] the tag to show details for
176
+ # @param options [Hash] the options hash containing date range
177
+ # @return [void]
178
+ #
179
+ # @example
180
+ # worklog.tag_detail('example_tag', from: '2023-10-01', to: '2023-10-31')
181
+ def tag_detail(tag, options)
182
+ printer = Printer.new(@storage.load_people!)
183
+ start_date, end_date = start_end_date(options)
184
+
185
+ @storage.days_between(start_date, end_date).each do |daily_log|
186
+ next unless daily_log.tags.include?(tag)
187
+
188
+ daily_log.entries.each do |entry|
189
+ next unless entry.tags.include?(tag)
190
+
191
+ printer.print_entry(daily_log, entry, true)
192
+ end
193
+ end
194
+ end
195
+
156
196
  def stats(_options = {})
157
197
  stats = Statistics.new(@config).calculate
158
198
  puts "#{format_left('Total days')}: #{stats.total_days}"
@@ -207,9 +247,11 @@ class Worklog
207
247
  elsif options[:from]
208
248
  start_date = DateParser.parse_date_string!(options[:from], true)
209
249
  end_date = DateParser.parse_date_string!(options[:to], false) if options[:to]
210
- else
250
+ elsif options[:date]
211
251
  start_date = Date.strptime(options[:date], '%Y-%m-%d')
212
252
  end_date = start_date
253
+ else
254
+ raise ArgumentError, 'No date range specified. Use --days, --from, --to or --date options.'
213
255
  end
214
256
  [start_date, end_date]
215
257
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fewald-worklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald