ops_team 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/builtins/countdown.rb +74 -0
- data/ops_team.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 284cb7b523fa92a233a477d63adf73ca4257a460968fa135e722af70d7782e33
|
4
|
+
data.tar.gz: e9ec66dfe05a1411b5a3180cbffe5545ec23dfc193d06150c80a2cb96147bcd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f399f48ff25956007f5ee9f7ff043b01c06639d1c58ba6d2dbffbaac5705b33b6c0d94a8a323279b7781aa8a199b8076c3f98e645b9e1a27c1e418cffd4c876
|
7
|
+
data.tar.gz: 0abe327dc2b32a4a82124a1de5f83e71f2d2674b2d3d102cd96db47a4dbed316d094d9041c9f2a2d729176c0cd2cc4ee1c393726f659d4a8d1460e2a1ac03ec6
|
data/Gemfile
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'concurrent'
|
4
|
+
|
5
|
+
require 'builtin'
|
6
|
+
require 'output'
|
7
|
+
|
8
|
+
module Builtins
|
9
|
+
class Countdown < Builtin
|
10
|
+
USAGE_STRING = "Usage: ops countdown <seconds>"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def description
|
14
|
+
"Like `sleep`, but displays time remaining in terminal."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
check_args
|
20
|
+
|
21
|
+
timer_task.execute
|
22
|
+
|
23
|
+
while timer_task.running?
|
24
|
+
sleep(1)
|
25
|
+
timer_task.shutdown if task_complete?
|
26
|
+
end
|
27
|
+
Output.out("\rCountdown complete after #{sleep_seconds}s.")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def check_args
|
33
|
+
check_arg_count
|
34
|
+
check_arg_is_positive_int
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_arg_count
|
38
|
+
raise Builtin::ArgumentError, USAGE_STRING unless args.length == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_arg_is_positive_int
|
42
|
+
raise Builtin::ArgumentError, USAGE_STRING unless sleep_seconds.positive?
|
43
|
+
# raised when the arg is not an int
|
44
|
+
rescue ::ArgumentError
|
45
|
+
raise Builtin::ArgumentError, USAGE_STRING
|
46
|
+
end
|
47
|
+
|
48
|
+
def timer_task
|
49
|
+
@timer_task ||= Concurrent::TimerTask.new(run_now: true, execution_interval: 1) do
|
50
|
+
Output.print("\r#{seconds_left}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sleep_seconds
|
55
|
+
Integer(args.first)
|
56
|
+
end
|
57
|
+
|
58
|
+
def task_start_time
|
59
|
+
@task_start_time ||= Time.now
|
60
|
+
end
|
61
|
+
|
62
|
+
def task_end_time
|
63
|
+
@task_end_time ||= task_start_time + sleep_seconds
|
64
|
+
end
|
65
|
+
|
66
|
+
def task_complete?
|
67
|
+
Time.now > task_end_time
|
68
|
+
end
|
69
|
+
|
70
|
+
def seconds_left
|
71
|
+
Integer(task_end_time - Time.now + 1)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/ops_team.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ops_team
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- lib/builtin.rb
|
153
153
|
- lib/builtins/background.rb
|
154
154
|
- lib/builtins/background_log.rb
|
155
|
+
- lib/builtins/countdown.rb
|
155
156
|
- lib/builtins/down.rb
|
156
157
|
- lib/builtins/env.rb
|
157
158
|
- lib/builtins/envdiff.rb
|