fewald-worklog 0.2.12 → 0.2.13
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 +4 -4
- data/.version +1 -1
- data/lib/cli.rb +1 -1
- data/lib/configuration.rb +28 -23
- data/lib/editor.rb +1 -1
- data/lib/worklog.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 190a52d7236e8befad053e79f9fbba8f32f149e354695148a73b732b21172e6b
|
4
|
+
data.tar.gz: 5bbd3f3a1200119a20288eb59889bd7498c8d08a01e6ebbc1506b95dd8233e38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2a075eeda5349c0190ce4a6420c5bd6b34759ffdf11845227f9c4fc89d2b522ba095c5059abb19b8c4508c7eaf0a2faf72ac6a980844bd89e6d5dde7d982052
|
7
|
+
data.tar.gz: 8af5b16a3b3288f5c124d59442d76e83a0d6743ad5a34de5d4c930d3217c0277809082c8fe9c4b2045bf77311c03617b4fb9d5c4b9f495045b737d9a21345efc
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.13
|
data/lib/cli.rb
CHANGED
@@ -30,7 +30,7 @@ class WorklogCLI < Thor
|
|
30
30
|
|
31
31
|
# Initialize the CLI with the given arguments, options, and configuration
|
32
32
|
def initialize(args = [], options = {}, config = {})
|
33
|
-
@config =
|
33
|
+
@config = Worklog::Configuration.load
|
34
34
|
@storage = Storage.new(@config)
|
35
35
|
super
|
36
36
|
end
|
data/lib/configuration.rb
CHANGED
@@ -3,32 +3,37 @@
|
|
3
3
|
require 'worklogger'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
|
7
|
-
class
|
8
|
-
|
6
|
+
module Worklog
|
7
|
+
# Configuration class for the application.
|
8
|
+
class Configuration
|
9
|
+
attr_accessor :storage_path, :log_level, :webserver_port
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def initialize(&block)
|
12
|
+
block.call(self) if block_given?
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
# Set default values if not set
|
15
|
+
@storage_path ||= File.join(Dir.home, '.worklog')
|
16
|
+
@log_level = log_level || :info
|
17
|
+
@log_level = @log_level.to_sym if @log_level.is_a?(String)
|
18
|
+
@webserver_port ||= 3000
|
19
|
+
end
|
20
|
+
|
21
|
+
# Load configuration from a YAML file in the user's home directory.
|
22
|
+
# If the file does not exist, it will use default values.
|
23
|
+
# @return [Configuration] the loaded configuration
|
24
|
+
def self.load
|
25
|
+
file_path = File.join(Dir.home, '.worklog.yaml')
|
26
|
+
config = Configuration.new
|
27
|
+
if File.exist?(file_path)
|
28
|
+
file_cfg = YAML.load_file(file_path)
|
29
|
+
config.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
|
30
|
+
config.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
|
31
|
+
config.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']
|
32
|
+
else
|
33
|
+
WorkLogger.debug "Configuration file does not exist in #{file_path}, using defaults."
|
34
|
+
end
|
19
35
|
|
20
|
-
|
21
|
-
# The file should be located at ~/.worklog.yaml.
|
22
|
-
def load_configuration
|
23
|
-
file_path = File.join(Dir.home, '.worklog.yaml')
|
24
|
-
if File.exist?(file_path)
|
25
|
-
file_cfg = YAML.load_file(file_path)
|
26
|
-
Configuration.new do |cfg|
|
27
|
-
cfg.storage_path = file_cfg['storage_path'] if file_cfg['storage_path']
|
28
|
-
cfg.log_level = file_cfg['log_level'].to_sym if file_cfg['log_level']
|
29
|
-
cfg.webserver_port = file_cfg['webserver_port'] if file_cfg['webserver_port']
|
36
|
+
config
|
30
37
|
end
|
31
|
-
else
|
32
|
-
WorkLogger.debug "Configuration file does not exist in #{file_path}"
|
33
38
|
end
|
34
39
|
end
|
data/lib/editor.rb
CHANGED
@@ -7,7 +7,7 @@ require 'tempfile'
|
|
7
7
|
module Editor
|
8
8
|
EDITOR_PREAMBLE = ERB.new <<~README
|
9
9
|
# Edit the content below, then save the file and quit the editor.
|
10
|
-
# The
|
10
|
+
# The updated content will be saved. The content MUST be valid YAML
|
11
11
|
# in order for the application to be able to update the records.
|
12
12
|
|
13
13
|
<%= content %>
|
data/lib/worklog.rb
CHANGED
@@ -5,6 +5,7 @@ require 'optparse'
|
|
5
5
|
require 'rainbow'
|
6
6
|
require 'yaml'
|
7
7
|
|
8
|
+
require 'configuration'
|
8
9
|
require 'hash'
|
9
10
|
require 'daily_log'
|
10
11
|
require 'date_parser'
|
@@ -332,6 +333,7 @@ module Worklog
|
|
332
333
|
rescue Errno::ENOENT
|
333
334
|
raise ProjectNotFoundError, 'No projects found. Please create a project first.'
|
334
335
|
end
|
336
|
+
WorkLogger.debug "Project with key '#{project_key}' exists."
|
335
337
|
return if projects.key?(project_key)
|
336
338
|
|
337
339
|
raise ProjectNotFoundError, "Project with key '#{project_key}' does not exist."
|