time_block 0.1.0 → 0.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 +4 -4
- data/lib/time_block/agent.rb +7 -2
- data/lib/time_block/cli.rb +11 -3
- data/lib/time_block/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a964dbdb28c131ce8b552e6cba90787838888e8
|
4
|
+
data.tar.gz: 9a7e9dd402665a1b0e7e79257f37be835ea225a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ec9329e1faf1145ae66915b51b3ee855a1cbc510ac3f513c2c7c81b1834bf94b99eb215f194414474b552a9e570c5368e29cd1c019756277f89a48e505d2a8
|
7
|
+
data.tar.gz: a7bb8be9b2b0c237f3d4cf6da65ef4cc9048fdb69d40b4e343785e9d4c51c9904d4146f12afbf3665f7fa639aa33ad6ff23c3def32516c76f68e883377845de7
|
data/lib/time_block/agent.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'English'
|
4
|
+
|
3
5
|
module TimeBlock
|
4
6
|
class Agent
|
7
|
+
|
8
|
+
class MissingPackageError < StandardError; end
|
9
|
+
|
5
10
|
def initialize(time)
|
6
|
-
raise 'No terminal-notifier, please install it, brew install terminal-notifier' unless terminal_notifier_exist?
|
11
|
+
raise MissingPackageError.new('No terminal-notifier, please install it, brew install terminal-notifier') unless terminal_notifier_exist?
|
7
12
|
@time = time
|
8
13
|
end
|
9
14
|
|
@@ -17,7 +22,7 @@ module TimeBlock
|
|
17
22
|
|
18
23
|
def terminal_notifier_exist?
|
19
24
|
`which terminal-notifier`
|
20
|
-
$CHILD_STATUS.
|
25
|
+
$CHILD_STATUS.success?
|
21
26
|
end
|
22
27
|
|
23
28
|
def pre_callback
|
data/lib/time_block/cli.rb
CHANGED
@@ -11,9 +11,11 @@ module TimeBlock
|
|
11
11
|
class UnsupportedCommand < StandardError; end
|
12
12
|
|
13
13
|
def run
|
14
|
-
parse_args
|
14
|
+
parse_args!
|
15
15
|
set_defaults
|
16
16
|
execute
|
17
|
+
rescue UnsupportedCommand => e
|
18
|
+
puts e.message
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
@@ -28,6 +30,7 @@ module TimeBlock
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def start
|
33
|
+
puts "Time #{@time}s ..."
|
31
34
|
Dante::Runner
|
32
35
|
.new('timeblock')
|
33
36
|
.execute(daemonize: true, pid_path: pid_path, log_path: log_path) do |_opts|
|
@@ -54,7 +57,7 @@ module TimeBlock
|
|
54
57
|
@verbose ||= false
|
55
58
|
end
|
56
59
|
|
57
|
-
def parse_args
|
60
|
+
def parse_args!
|
58
61
|
opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
|
59
62
|
['--time', '-t', GetoptLong::REQUIRED_ARGUMENT],
|
60
63
|
['--verbose', '-v', GetoptLong::NO_ARGUMENT])
|
@@ -67,6 +70,11 @@ module TimeBlock
|
|
67
70
|
exit(0)
|
68
71
|
when '--time'
|
69
72
|
@time = arg.to_i
|
73
|
+
if arg.chars.last == 'm'
|
74
|
+
@time *= 60
|
75
|
+
elsif arg.chars.last == 'h'
|
76
|
+
@time *= 60 * 24
|
77
|
+
end
|
70
78
|
when '--verbose'
|
71
79
|
@verbose = true
|
72
80
|
end
|
@@ -78,7 +86,7 @@ module TimeBlock
|
|
78
86
|
end
|
79
87
|
|
80
88
|
def supported_commands?(cmd)
|
81
|
-
|
89
|
+
%w[stop start restart].include?(cmd)
|
82
90
|
end
|
83
91
|
|
84
92
|
def print_help
|
data/lib/time_block/version.rb
CHANGED