work_hours_calculator 0.3.0 → 1.0.0
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/README.md +5 -5
- data/lib/work_hours_calculator/parser.rb +42 -10
- data/lib/work_hours_calculator/version.rb +1 -1
- 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: 7c56f600afa7dec0462adc0dcaa24efef4ac176e27bd1d3ff1c4de08ebc48abc
|
4
|
+
data.tar.gz: c810213e848ae289894099780852ef9db710b7cfdd2e6fcec654fe80a6226bbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52a84c43725e1173f59cd9bdb6ecd6220a057fb048423395bcb8b8015efbaf3046166b7bb6c8ff8bcf4993aebd74d8d20637076db065259b7d5f2409a4e16cb7
|
7
|
+
data.tar.gz: cb8924d6cf5e184acddd776d886bc99fa8dbbe55963b8937f747a5a84fc6a09e9d1771bd54d75d09db21ab9b12b50aaf7d6402824f81df05ef8e56f67338a60d
|
data/README.md
CHANGED
@@ -87,11 +87,11 @@ Run the script from the command line with the required options for start time, e
|
|
87
87
|
| -s or --start-time | Specifies the work start time | `-s "9:30:00 AM"` |
|
88
88
|
| -e or --end-time | Specifies the work end time | `-e "6:00:00 PM"` |
|
89
89
|
| -b or --breaks | Specifies break periods in comma-separated start_time-end_time format | `-b "12:49:00 PM-1:26:00 PM,3:42:00 PM-4:35:00 PM"` |
|
90
|
-
| --csv-input | Specifies the CSV input file | `--csv-input path/to/your/input.csv`s |
|
91
|
-
| --csv-output | Specifies the CSV output file | `--csv-output path/to/your/output.csv` |
|
92
|
-
| --log DESCRIPTION | Log work with description | `--log "working on a project"` |
|
93
|
-
| --log-dir DIRECTORY | Specify a directory to store log files | `--lod-dir` <br><br>or export it as an ENV variable so you don't have to specify the directory arg everytime. <br> `export WORK_HOURS_LOG_DIR="/some/path"`|
|
94
|
-
| --calculate-log DATE | Calculate hours from the log file for the specified date (e.g., '2023-10-01') | `--calculate-log 2025-02-01` |
|
90
|
+
| -i, --csv-input | Specifies the CSV input file | `--csv-input path/to/your/input.csv`s |
|
91
|
+
| -o, --csv-output | Specifies the CSV output file | `--csv-output path/to/your/output.csv` |
|
92
|
+
| -l, --log DESCRIPTION | Log work with description | `--log "working on a project"` |
|
93
|
+
| -dir, --log-dir DIRECTORY | Specify a directory to store log files | `--lod-dir` <br><br>or export it as an ENV variable so you don't have to specify the directory arg everytime. <br> `export WORK_HOURS_LOG_DIR="/some/path"`|
|
94
|
+
| -t, --calculate-log DATE | Calculate hours from the log file for the specified date (e.g., '2023-10-01') | `--calculate-log 2025-02-01` |
|
95
95
|
| -h or --help | Displays help instructions | `-h` |
|
96
96
|
|
97
97
|
|
@@ -4,43 +4,75 @@ require "optparse"
|
|
4
4
|
|
5
5
|
# Parses command-line options for the work calculator.
|
6
6
|
module WorkHoursCalculator
|
7
|
+
class ParserError < StandardError; end
|
8
|
+
|
9
|
+
class MissingOptionError < ParserError; end
|
10
|
+
|
11
|
+
class InvalidOptionError < ParserError; end
|
12
|
+
|
7
13
|
class Parser
|
8
14
|
def self.parse_options(args = ARGV)
|
9
15
|
options = {}
|
10
16
|
OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage: work_calculator
|
17
|
+
opts.banner = "Usage: work_calculator [options] arg"
|
12
18
|
|
19
|
+
opts.separator ""
|
20
|
+
opts.separator "General Options:"
|
13
21
|
opts.on("-s", "--start-time START", "Work start time (e.g., '9:30:00 AM')") { |v| options[:start_time] = v }
|
14
22
|
opts.on("-e", "--end-time END", "Work end time (e.g., '6:00:00 PM')") { |v| options[:end_time] = v }
|
15
23
|
opts.on("-b", "--breaks x,y", Array, "Break periods as comma-separated pairs (e.g., '12:49:00 PM-1:26:00 PM,3:42:00 PM-4:35:00 PM')") { |v| options[:breaks] = v.map { |pair| pair.split("-") } }
|
16
|
-
|
17
|
-
opts.
|
18
|
-
opts.
|
24
|
+
|
25
|
+
opts.separator ""
|
26
|
+
opts.separator "CSV File Options:"
|
27
|
+
opts.on("-i", "--csv-input FILE", "CSV input file") { |v| options[:csv_input] = v }
|
28
|
+
opts.on("-o", "--csv-output FILE", "CSV output file") { |v| options[:csv_output] = v }
|
29
|
+
|
30
|
+
opts.separator ""
|
31
|
+
opts.separator "Work hour logging Options:"
|
32
|
+
opts.on("-l", "--log DESCRIPTION", "Log work with description") { |v|
|
19
33
|
options[:log] = true
|
20
34
|
options[:description] = v
|
21
35
|
}
|
22
|
-
opts.on("--
|
23
|
-
opts.on("--calculate-log DATE", "Calculate hours from the log file for the specified date (e.g., '2023-10-01')") { |v|
|
36
|
+
opts.on("--dir DIRECTORY", "Directory to store log files") { |v| options[:log_dir] = v }
|
37
|
+
opts.on("-t", "--calculate-log DATE", "Calculate hours from the log file for the specified date (e.g., '2023-10-01')") { |v|
|
24
38
|
options[:calculate_log] = true
|
25
39
|
options[:log_date] = v
|
26
40
|
}
|
41
|
+
|
42
|
+
opts.separator ""
|
43
|
+
opts.separator "Setup your log directory via environment variable:"
|
44
|
+
opts.separator ""
|
45
|
+
opts.separator "export WORK_HOURS_LOG_DIR='/some/path'"
|
46
|
+
|
47
|
+
opts.separator ""
|
48
|
+
opts.separator ""
|
49
|
+
opts.separator "For more information:"
|
27
50
|
opts.on("-h", "--help", "Show help") {
|
28
51
|
puts opts
|
29
52
|
exit
|
30
53
|
}
|
54
|
+
|
55
|
+
opts.separator ""
|
56
|
+
opts.separator "=============================================="
|
57
|
+
opts.separator ""
|
58
|
+
opts.separator "Thank you for supporting open source projects."
|
59
|
+
opts.separator "For bugs or feature requests, visit https://github.com/gerdadecio/work-hours-calculator-ruby"
|
60
|
+
opts.separator "Author: Gerda Decio, https://github.com/gerdadecio"
|
31
61
|
end.parse!(args, into: options)
|
32
62
|
|
33
63
|
if (options[:csv_input].nil? && options[:log].nil? && options[:calculate_log].nil?) && (options[:start_time].nil? || options[:end_time].nil? || options[:breaks].nil?)
|
34
|
-
|
35
|
-
exit
|
64
|
+
raise MissingOptionError, "Please provide start time, end time, and break times, or a CSV input file."
|
36
65
|
end
|
37
66
|
|
38
67
|
if options[:log] && options[:description].nil?
|
39
|
-
|
40
|
-
exit 1
|
68
|
+
raise MissingOptionError, "Description is required when logging work hours."
|
41
69
|
end
|
42
70
|
|
43
71
|
options
|
72
|
+
rescue OptionParser::MissingArgument, WorkHoursCalculator::MissingOptionError => e
|
73
|
+
puts e.message
|
74
|
+
puts "\nfor more information: work_calculator --help"
|
75
|
+
exit
|
44
76
|
end
|
45
77
|
end
|
46
78
|
end
|