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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0326ed47ce090f45118f068bfbc92f8d3dddea710c08e5623202ac76e1478ebd
4
- data.tar.gz: 0bae3c9e5f6079a3286acf59c32af5f72bfbc47f0365a4c6c2f6efff49576ed4
3
+ metadata.gz: 284cb7b523fa92a233a477d63adf73ca4257a460968fa135e722af70d7782e33
4
+ data.tar.gz: e9ec66dfe05a1411b5a3180cbffe5545ec23dfc193d06150c80a2cb96147bcd9
5
5
  SHA512:
6
- metadata.gz: c640ee9e260aba54f559750b02ccd9edfc9153ebf2dbc41422b19de8b5321e8502145d3766dcce8f16518972ab7f09b39aa3a0e984801f23d8e5c5e68d64213a
7
- data.tar.gz: b59dcbb2c7e09f264d8a98ffa9a580508c5a7455e6b8cccb9fdd7259cc4e068cf2602c0834635a7627eddb0d5660358cec49d1c75c62fb4b8f600cb9c3296f77
6
+ metadata.gz: 4f399f48ff25956007f5ee9f7ff043b01c06639d1c58ba6d2dbffbaac5705b33b6c0d94a8a323279b7781aa8a199b8076c3f98e645b9e1a27c1e418cffd4c876
7
+ data.tar.gz: 0abe327dc2b32a4a82124a1de5f83e71f2d2674b2d3d102cd96db47a4dbed316d094d9041c9f2a2d729176c0cd2cc4ee1c393726f659d4a8d1460e2a1ac03ec6
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  gem "bcrypt_pbkdf"
8
8
  gem "colorize"
9
+ gem 'concurrent-ruby', require: 'concurrent'
9
10
  gem "e2mmap"
10
11
  gem "ed25519"
11
12
  gem "ejson"
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '1.2.4'
5
+ s.version = '1.3.0'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
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.2.4
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