ptimelog 0.6.0 → 0.7.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
  SHA256:
3
- metadata.gz: 53f453d27b45af79d5bef690d87c5ad36984848f3df02a3114cc60fb3e4a4dbf
4
- data.tar.gz: 77c4269e3d12bc42db29624bf4b06e2092f1c60459d13aed8a2d3bf28e03ba12
3
+ metadata.gz: f72b05fa5e616ace4ab1279b49b23bba94f5130edd06f54a1e8b21bda1a67d35
4
+ data.tar.gz: 334c78339b815942e0c3155d49ee8bb601603ab682936f240370eeeabe209196
5
5
  SHA512:
6
- metadata.gz: 6db9a06490897de96ca955ad900876f8848482a2dfe1796cdf1f0dfdbb35ed0d44f61616e2c00fa56acc1cc427b3e39645b37fc65cf7144f55f414fd762fc15b
7
- data.tar.gz: d6e38738b5f4384b03edac240bdcd7622e2812d8d056529d26d10903b6d1e73e3c72e1f3b4bfede1e4a234c5738ec8171d0385d276f3ab7843a8675759361251
6
+ metadata.gz: 400d45182b50402b0832adb98b4c31ea84ff1c5fb9b815c43ba9d575257f9bb371d7db920270399d74f97a6f2a6bb9d7b57d1a35cff4bdf3e15d0a085a0f7295
7
+ data.tar.gz: 5b8c16be0f1a3c6b3b4ae01442abaf10c381d860922cf84c58abc097ab9f1d1c82deb235e4857f58ca0b75654bc3df34b716d413a2692876e73e101e0e13f85c
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ PATH_add exe
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /spec/state.txt
data/README.md CHANGED
@@ -27,7 +27,7 @@ small tooling to transfer timelog-entries from gtimelog's timelog.txt to the Puz
27
27
  - [ ] avoid duplicate entries
28
28
  - [ ] start/end time as indicator?
29
29
  - [x] offer rounding times to the next 5, 10 or 15 minutes
30
- - [ ] allow to add entries from the command-line
30
+ - [x] allow to add entries from the command-line
31
31
  - [ ] handle time-account and billable better
32
32
  - [ ] import time-accounts from ptime (https://time.puzzle.ch/work_items/search.json?q=search%20terms)
33
33
  - [ ] with a dedicated cli?
data/lib/ptimelog.rb CHANGED
@@ -6,6 +6,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
6
6
  module Ptimelog
7
7
  autoload :App, 'ptimelog/app'
8
8
  autoload :Configuration, 'ptimelog/configuration'
9
+ autoload :Day, 'ptimelog/day'
9
10
  autoload :DeprecationWarning, 'ptimelog/deprecation_warning'
10
11
  autoload :Entry, 'ptimelog/entry'
11
12
  autoload :NamedDate, 'ptimelog/named_date'
@@ -16,6 +17,7 @@ module Ptimelog
16
17
 
17
18
  # Collection of commands available at the CLI
18
19
  module Command
20
+ autoload :Add, 'ptimelog/command/add'
19
21
  autoload :Base, 'ptimelog/command/base'
20
22
  autoload :Edit, 'ptimelog/command/edit'
21
23
  autoload :Show, 'ptimelog/command/show'
data/lib/ptimelog/app.rb CHANGED
@@ -1,58 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ptimelog
4
- # Wrapper for everything
4
+ # Wrapper for everything, dispatching to a command
5
5
  class App
6
6
  def initialize(args)
7
7
  @config = Configuration.instance
8
- command = (args[0] || :show).to_sym
8
+ command = (args[0] || 'show')
9
9
 
10
- @command = case command
11
- when :show
12
- @date = NamedDate.new.date(args[1])
13
- Command::Show.new
14
- when :upload
15
- @date = NamedDate.new.date(args[1])
16
- Command::Upload.new
17
- when :edit
18
- file = args[1]
19
- Command::Edit.new(file)
20
- else
21
- raise ArgumentError, "Unsupported Command #{@command}"
22
- end
10
+ constant_name = command.to_s[0].upcase + command[1..-1].downcase
11
+ command_class = Command.const_get(constant_name.to_sym)
12
+ raise ArgumentError, "Unsupported Command '#{command}'" if command_class.nil?
13
+
14
+ @command = command_class.new(args[1]) # e.g. Ptimelog::Command::Show.new('today')
23
15
  end
24
16
 
25
17
  def run
26
- @command.entries = entries if @command.needs_entries?
27
-
28
18
  @command.run
29
19
  end
30
-
31
- private
32
-
33
- def timelog
34
- Timelog.load
35
- end
36
-
37
- def entries
38
- timelog.each_with_object({}) do |(date, lines), entries|
39
- next unless date # guard against the machine
40
- next unless @date == :all || @date == date # limit to one day if passed
41
-
42
- entries[date] = []
43
- start = nil # at the start of the day, we have no previous end
44
-
45
- lines.each do |line|
46
- entry = Entry.from_timelog(line)
47
- entry.start_time = start
48
-
49
- entries[date] << entry if entry.valid?
50
-
51
- start = entry.finish_time # store previous ending for nice display of next entry
52
- end
53
-
54
- entries
55
- end
56
- end
57
20
  end
58
21
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Ptimelog
6
+ module Command
7
+ # add a new entrie with the current date and time
8
+ class Add < Base
9
+ def initialize(task)
10
+ super()
11
+
12
+ @task = task
13
+ @timelog = Ptimelog::Timelog.instance
14
+ end
15
+
16
+ def needs_entries?
17
+ false
18
+ end
19
+
20
+ def run
21
+ date_time = Time.now.strftime('%F %R')
22
+
23
+ @timelog.timelog_txt.open('a') do |log|
24
+ log << "#{date_time}: #{@task}\n"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -4,9 +4,12 @@ module Ptimelog
4
4
  module Command
5
5
  # Foundation and common API for all commands
6
6
  class Base
7
- def initialize
8
- @config = Configuration.instance
9
- @entries = {} if needs_entries?
7
+ def initialize(day = nil)
8
+ @config = Configuration.instance
9
+
10
+ return unless needs_entries?
11
+
12
+ @entries = Ptimelog::Day.new(day).entries
10
13
  end
11
14
 
12
15
  def needs_entries?
@@ -28,8 +28,6 @@ module Ptimelog
28
28
  %i[
29
29
  timelog
30
30
  existing_inferer
31
- existing_parser
32
- billable
33
31
  empty_inferer
34
32
  ].each do |file_lookup|
35
33
  valid, filename = send(file_lookup, requested_file)
@@ -48,23 +46,9 @@ module Ptimelog
48
46
  [fn.exist?, fn]
49
47
  end
50
48
 
51
- def existing_parser(file)
52
- fn = @scripts.parser(file)
53
-
54
- [fn.exist?, fn]
55
- end
56
-
57
- def billable(file)
58
- [file == 'billable', @scripts.billable]
59
- end
60
-
61
49
  def empty_inferer(file)
62
50
  [true, @scripts.inferer(file)]
63
51
  end
64
-
65
- def empty_parser(file)
66
- [true, @scripts.parser(file)]
67
- end
68
52
  end
69
53
  end
70
54
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ptimelog
4
+ # Wrap loading of all entries of a day
5
+ class Day
6
+ def initialize(date)
7
+ @date = NamedDate.new.date(date)
8
+ end
9
+
10
+ def entries
11
+ timelog.each_with_object({}) do |(date, lines), entries|
12
+ next unless date # guard against the machine
13
+ next unless @date == :all || @date == date # limit to one day if passed
14
+
15
+ entries[date] = []
16
+ start = nil # at the start of the day, we have no previous end
17
+
18
+ lines.each do |line|
19
+ entry = Entry.from_timelog(line)
20
+ entry.start_time = start
21
+
22
+ entries[date] << entry if entry.valid?
23
+
24
+ start = entry.finish_time # store previous ending for nice display of next entry
25
+ end
26
+
27
+ entries
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def timelog
34
+ Timelog.load
35
+ end
36
+ end
37
+ end
@@ -63,16 +63,11 @@ module Ptimelog
63
63
  @billable == BILLABLE
64
64
  end
65
65
 
66
- # this method will be reduced in 0.7, when support for parsers is removed
67
66
  def infer_ptime_settings
68
67
  return if hidden?
68
+ return unless @script.inferer(script_name).exist?
69
69
 
70
- if @script.inferer(script_name).exist?
71
- @account, @billable = infer_account_and_billable
72
- else
73
- @account = infer_account
74
- @billable = infer_billable
75
- end
70
+ @account, @billable = infer_account_and_billable
76
71
  end
77
72
 
78
73
  def to_s
@@ -109,27 +104,6 @@ module Ptimelog
109
104
  @script_args ||= @tags.to_a[1..-1].to_a.map(&:inspect).join(' ')
110
105
  end
111
106
 
112
- # this method will be removed in 0.7, when support for parsers is removed
113
- def infer_account
114
- parser = @script.parser(script_name)
115
- return unless parser.exist?
116
-
117
- @script.deprecate(parser)
118
-
119
- cmd = %(#{parser} "#{@ticket}" "#{@description}" #{script_args})
120
- `#{cmd}`.chomp # maybe only execute if parser is in correct dir?
121
- end
122
-
123
- # this method will be removed in 0.7, when support for billable is removed
124
- def infer_billable
125
- script = @script.billable
126
- return BILLABLE unless script.exist?
127
-
128
- @script.deprecate(script)
129
-
130
- `#{script} #{@account}`.chomp == 'true' ? BILLABLE : NON_BILLABLE
131
- end
132
-
133
107
  def infer_account_and_billable
134
108
  script = @script.inferer(script_name)
135
109
 
@@ -8,35 +8,11 @@ module Ptimelog
8
8
  @config_dir = config_dir
9
9
  end
10
10
 
11
- def parser(parser_name)
12
- @config_dir.join("parsers/#{parser_name}") # FIXME: security-hole, prevent relative paths!
13
- .expand_path
14
- end
15
-
16
- def billable
17
- @config_dir.join('billable').expand_path
18
- end
19
-
20
11
  def inferer(name)
21
12
  return NullPathname.new if name.to_s.empty?
22
13
  raise if name =~ %r{[\\/]} # prevent relavtive paths, stupidly, FIXME: really check FS
23
14
 
24
15
  @config_dir.join('inferers').join(name).expand_path
25
16
  end
26
-
27
- include DeprecationWarning
28
-
29
- def deprecate_message(_)
30
- <<~MESSAGE
31
- Please move the parser- and billable-scripts to an inferer-script.
32
- Support for the previous scripts in parsers/* and billable will
33
- be dropped in 0.7.
34
-
35
- MESSAGE
36
- end
37
-
38
- def deprecate_header(script_fn)
39
- "DEPRECATION NOTICE: #{script_fn} is deprecated"
40
- end
41
17
  end
42
18
  end
@@ -16,5 +16,5 @@
16
16
  # with an improvement. Keep in mind that this is also covered by rspec so I
17
17
  # expect (pun intended) 100% test-coverage for any additional code.
18
18
  module Ptimelog
19
- VERSION = '0.6.0'
19
+ VERSION = '0.7.0'
20
20
  end
data/ptimelog.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'bundler'
28
28
  spec.add_development_dependency 'overcommit', '~> 0.45'
29
29
  spec.add_development_dependency 'pry', '~> 0.12'
30
- spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rake', '>= 12.3.3'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
32
  spec.add_development_dependency 'rubocop', '~> 0.50'
33
33
  spec.add_development_dependency 'timecop', '~> 0.9'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptimelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Viehweger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2020-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: naught
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: 12.3.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: 12.3.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -130,6 +130,7 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
+ - ".envrc"
133
134
  - ".gitignore"
134
135
  - ".overcommit.yml"
135
136
  - ".rspec"
@@ -147,11 +148,13 @@ files:
147
148
  - exe/ptimelog
148
149
  - lib/ptimelog.rb
149
150
  - lib/ptimelog/app.rb
151
+ - lib/ptimelog/command/add.rb
150
152
  - lib/ptimelog/command/base.rb
151
153
  - lib/ptimelog/command/edit.rb
152
154
  - lib/ptimelog/command/show.rb
153
155
  - lib/ptimelog/command/upload.rb
154
156
  - lib/ptimelog/configuration.rb
157
+ - lib/ptimelog/day.rb
155
158
  - lib/ptimelog/deprecation_warning.rb
156
159
  - lib/ptimelog/entry.rb
157
160
  - lib/ptimelog/named_date.rb
@@ -179,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
182
  - !ruby/object:Gem::Version
180
183
  version: '0'
181
184
  requirements: []
182
- rubygems_version: 3.0.3
185
+ rubygems_version: 3.1.2
183
186
  signing_key:
184
187
  specification_version: 4
185
188
  summary: Move time-entries from gTimelog to PuzzleTime