kobot 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00f2c1151ffcb202b20d4b3f9881c9570b1075ea3684f7ab3ea2cfc65baf4b33
4
- data.tar.gz: a6f3da0260abbbfce192557ea580526698b828ed19ec7175dd64080fa437ba35
3
+ metadata.gz: c867dcb791e15db7a407fc9dc0898ad49e9dccba53514f98ad32b253f1fc8adc
4
+ data.tar.gz: 6887ebe669b7628a7972a89d2b508b498f5ce856fe80d98e85a52c3bcedfd377
5
5
  SHA512:
6
- metadata.gz: 4fb7e982db990bdbf659009501f3eb028d02fdddf7e8d6ea48762495867196f5dfc748c6d14926d5239b57c4433dad3d2568c8d6ca9bf42d6de401b91391e7a3
7
- data.tar.gz: '06482f411bfbf8f0083d0750e7d8ea4074f6740de3e9b1d6ba27c3e850356cd28c39d83d3a27f5d99bf7e21589cce65d64396793ffd018180ec621f926db7327'
6
+ metadata.gz: 8ed4028a1a25f75cfa21370c41b72a7fbe66916c442279f7985b3dc6f1be6e540395b81292931549b53496b7db026ec0ca33f9c743623176207d31bf1b740aa4
7
+ data.tar.gz: b53a002259ad6312ae6437d11320b9b12f8d62e3ac26a01ed4e3dc48399cfb9d2f572384aebc2c3930014bf77e83c6351c7e7cf051b5eab02a87db33e31f7f51
@@ -5,3 +5,7 @@
5
5
  - Deprecated lower-case environment variables for credentials configuration
6
6
  - Updated option help doc to indicate weekends and public holidays are skipped by default
7
7
  - Updated required_ruby_version to be >= 2.4.0 to align with the webdrivers dependency
8
+
9
+ ### v1.2.0
10
+ - Added an option to allow forcibly running regardless of weekends or public holidays
11
+ - Added an ENV flag to allow requiring lib in local workspace for development purpose
data/README.md CHANGED
@@ -57,15 +57,17 @@ Get help doc:
57
57
  ```
58
58
  $ kobot -h
59
59
  Usage: kobot [options]
60
- -c, --clock CLOCK The clock action: in, out
61
- -l, --loglevel [LEVEL] Specify log level: debug, info, warn, error. Default is info
60
+ -c, --clock CLOCK Required; the clock action option: in, out
61
+ -l, --loglevel [LEVEL] Specify log level: debug, info, warn, error; default is info
62
62
  -s, --skip [D1,D2,D3] Specify dates to skip clock in/out with date format YYYY-MM-DD and
63
- multiple values separated by comma, such as: 2020-05-01,2020-12-31
64
- Weekends and public holidays in Japan are skipped by default.
65
- -t, --to [TO] Email address to send notification to. By default it is sent to
63
+ multiple values separated by comma, such as: 2020-05-01,2020-12-31;
64
+ weekends and public holidays in Japan will be skipped by default
65
+ -t, --to [TO] Email address to send notification to; by default it is sent to
66
66
  the same self email account used in SMTP config as the sender
67
67
  -n, --notify Enable email notification
68
68
  -d, --dryrun Run the process without actual clock in/out
69
+ -f, --force Run the process forcibly regardless of weekends or public holidays;
70
+ must be used together with --dryrun to prevent mistaken operations
69
71
  -x, --headless Start browser in headless mode
70
72
  -g, --geolocation Allow browser to use geolocation
71
73
  -h, --help Show this help message
data/exe/kobot CHANGED
@@ -1,6 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'kobot'
4
+ begin
5
+ # For quickly tryout in local development
6
+ # without installing to system gems path
7
+ raise LoadError if ENV['KOBOT_DEV']
8
+
9
+ require 'kobot'
10
+ rescue LoadError
11
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
12
+ require 'kobot'
13
+ end
5
14
 
6
15
  Kobot.run
@@ -33,6 +33,7 @@ module Kobot
33
33
  config.clock = options[:clock].to_sym
34
34
  config.loglevel = options[:loglevel]&.to_sym || :info
35
35
  config.dryrun = options[:dryrun]
36
+ config.force = options[:force]
36
37
  config.skip = options[:skip] || []
37
38
 
38
39
  config.kot_url = 'https://s2.kingtime.jp/independent/recorder/personal/'
@@ -9,7 +9,8 @@ module Kobot
9
9
  attr_accessor :clock,
10
10
  :loglevel,
11
11
  :skip,
12
- :dryrun
12
+ :dryrun,
13
+ :force
13
14
 
14
15
  attr_accessor :kot_url,
15
16
  :kot_timezone_offset,
@@ -26,11 +26,15 @@ module Kobot
26
26
  # to be popped up and should be handled by the outside caller.
27
27
  def start
28
28
  if weekend?
29
- Kobot.logger.info("Today=#{@today} is weekend.")
30
- return
29
+ if Config.force
30
+ Kobot.logger.info("[Force] should have exited: today=#{@today} is weekend")
31
+ else
32
+ Kobot.logger.info("Today=#{@today} is weekend")
33
+ return
34
+ end
31
35
  end
32
36
  if holiday?
33
- Kobot.logger.info("Today=#{@today} is holiday.")
37
+ Kobot.logger.info("Today=#{@today} is holiday")
34
38
  return
35
39
  end
36
40
  unless %i[in out].include? Config.clock
@@ -147,9 +151,29 @@ module Kobot
147
151
  end
148
152
 
149
153
  def verify_today_record!
150
- raise KotRecordError, "Today=#{@today} is not found on kot." if @kot_today.strip.empty?
151
- raise KotRecordError, "Today=#{@today} is marked as weekend on kot: #{@kot_today}" if kot_weekend?
152
- raise KotRecordError, "Today=#{@today} is marked as public holiday on kot: #{@kot_today}" if kot_public_holiday?
154
+ raise KotRecordError, "Today=#{@today} is not found on kot" if @kot_today.strip.empty?
155
+
156
+ if kot_weekend?
157
+ unless Config.force
158
+ raise KotRecordError,
159
+ "Today=#{@today} is marked as weekend on kot: #{@kot_today}"
160
+ end
161
+
162
+ Kobot.logger.info(
163
+ "[Force] should have exited: today=#{@today} is marked as weekend on kot: #{@kot_today}"
164
+ )
165
+ end
166
+
167
+ if kot_public_holiday?
168
+ unless Config.force
169
+ raise KotRecordError,
170
+ "Today=#{@today} is marked as public holiday on kot: #{@kot_today}"
171
+ end
172
+
173
+ Kobot.logger.info(
174
+ "[Force] should have exited: today=#{@today} is marked as public holiday on kot: #{@kot_today}"
175
+ )
176
+ end
153
177
  end
154
178
 
155
179
  def clock_in!
@@ -14,23 +14,23 @@ module Kobot
14
14
  opt_parser = OptionParser.new do |opt|
15
15
  opt.banner = "Usage: #{$PROGRAM_NAME} [options]"
16
16
 
17
- opt.on('-c', '--clock CLOCK', 'The clock action: in, out') do |clock|
17
+ opt.on('-c', '--clock CLOCK', 'Required; the clock action option: in, out') do |clock|
18
18
  options[:clock] = clock
19
19
  end
20
20
 
21
- opt.on('-l', '--loglevel [LEVEL]', 'Specify log level: debug, info, warn, error. Default is info') do |level|
21
+ opt.on('-l', '--loglevel [LEVEL]', 'Specify log level: debug, info, warn, error; default is info') do |level|
22
22
  options[:loglevel] = level
23
23
  end
24
24
 
25
25
  opt.on('-s', '--skip [D1,D2,D3]', Array,
26
26
  'Specify dates to skip clock in/out with date format YYYY-MM-DD and',
27
- 'multiple values separated by comma, such as: 2020-05-01,2020-12-31',
28
- 'Weekends and public holidays in Japan are skipped by default.') do |skip|
27
+ 'multiple values separated by comma, such as: 2020-05-01,2020-12-31;',
28
+ 'weekends and public holidays in Japan will be skipped by default') do |skip|
29
29
  options[:skip] = skip
30
30
  end
31
31
 
32
32
  opt.on('-t', '--to [TO]',
33
- 'Email address to send notification to. By default it is sent to',
33
+ 'Email address to send notification to; by default it is sent to',
34
34
  'the same self email account used in SMTP config as the sender') do |to|
35
35
  options[:to] = to
36
36
  end
@@ -43,6 +43,12 @@ module Kobot
43
43
  options[:dryrun] = dryrun
44
44
  end
45
45
 
46
+ opt.on('-f', '--force',
47
+ 'Run the process forcibly regardless of weekends or public holidays;',
48
+ 'must be used together with --dryrun to prevent mistaken operations') do |force|
49
+ options[:force] = force
50
+ end
51
+
46
52
  opt.on('-x', '--headless', 'Start browser in headless mode') do |headless|
47
53
  options[:headless] = headless
48
54
  end
@@ -63,7 +69,12 @@ module Kobot
63
69
  end
64
70
  opt_parser.parse! ARGV
65
71
  raise OptionParser::MissingArgument, 'The clock option is required' if options[:clock].nil?
66
- raise OptionParser::InvalidArgument, 'The clock option must be either: in, out' unless %w[in out].include? options[:clock]
72
+ unless %w[in out].include? options[:clock]
73
+ raise OptionParser::InvalidArgument, 'The clock option must be either: in, out'
74
+ end
75
+ if options[:force] && !options[:dryrun]
76
+ raise OptionParser::InvalidArgument, 'Must specify --dryrun for forcibly running'
77
+ end
67
78
 
68
79
  options
69
80
  rescue OptionParser::MissingArgument, OptionParser::InvalidArgument => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kobot
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jiang