klaxon 0.0.1
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/lib/klaxon.rb +114 -0
- data/lib/klaxon/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4d22bb6a0018d690618f4a543b2e8e10607e7c8fac0b035bdf9425397b5e3fbc
|
4
|
+
data.tar.gz: dce9a140888d4ce002d2985b92a5a051175fe9ddc53364d8dcd968f5a3ea12ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05d7d11b5327f4ee6903ce18a31160babb31cef4167017e8f15c83c47e6c4ee16fd18dc80d9ae0fb7931d0e8069a8421a3b093dc78ffdda5c2e0311ca627a15c
|
7
|
+
data.tar.gz: 4e5f9d00a9326936fcb7e8844b3a12d3d1b5e4cf9461b19d7537be703fe39355679138e1aa69a0916ddde4753ecb0960556d5a467bb4c66037cfeef76a220c54
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ryan Calhoun
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# klaxson
|
2
|
+
Insert a programmable interactive warning prompt for developers
|
3
|
+
before taking dangerous or destructive action.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
```ruby
|
7
|
+
Klaxon.alert banner: 'Delete', description: 'About to delete files!' do
|
8
|
+
system "rm -rf"
|
9
|
+
end
|
10
|
+
```
|
11
|
+
|
12
|
+
Prints to `STDERR`
|
13
|
+
```
|
14
|
+
_____ _ _
|
15
|
+
| __ \ | | | |
|
16
|
+
| | | | ___| | ___| |_ ___
|
17
|
+
| | | |/ _ \ |/ _ \ __/ _ \
|
18
|
+
| |__| | __/ | __/ |_ __/
|
19
|
+
|_____/ \___|_|\___|\__\___|
|
20
|
+
|
21
|
+
|
22
|
+
About to delete files!
|
23
|
+
To continue, press ENTER. To abort, press Ctrl+C...
|
24
|
+
```
|
25
|
+
|
26
|
+
### Using with YAML
|
27
|
+
The keyword args in the `alert` method work well with YAML symbol keys, and
|
28
|
+
can be mixed with existing YAML-based build configurations if desired.
|
29
|
+
|
30
|
+
Given a config like:
|
31
|
+
```yaml
|
32
|
+
---
|
33
|
+
dev:
|
34
|
+
:alert:
|
35
|
+
:banner: Development
|
36
|
+
:description: |
|
37
|
+
You are deploying to the dev environment
|
38
|
+
outside the CI pipleine.
|
39
|
+
:color: :yellow
|
40
|
+
prod:
|
41
|
+
:alert:
|
42
|
+
:banner: Production
|
43
|
+
:description: |
|
44
|
+
DANGER! You are deploying directly to
|
45
|
+
production outside the CI pipeline. This
|
46
|
+
is highly unusual and dangerous!
|
47
|
+
:color: :red
|
48
|
+
```
|
49
|
+
|
50
|
+
The args for `alert` can be passed like:
|
51
|
+
```ruby
|
52
|
+
Klaxon.alert YAML.load_file('config.yml').dig ENV['ENV'], :alert do
|
53
|
+
# deploy files...
|
54
|
+
end
|
55
|
+
```
|
data/lib/klaxon.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'artii'
|
2
|
+
require 'colorize'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'terminfo'
|
5
|
+
|
6
|
+
# Insert a programmable interactive warning prompt for developers
|
7
|
+
# before taking dangerous or destructive action.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# Klaxon.alert banner: 'Delete', description: 'About to delete files!' do
|
11
|
+
# system "rm -rf"
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # prints to STDERR...
|
15
|
+
# _____ _ _
|
16
|
+
# | __ \ | | | |
|
17
|
+
# | | | | ___| | ___| |_ ___
|
18
|
+
# | | | |/ _ \ |/ _ \ __/ _ \
|
19
|
+
# | |__| | __/ | __/ |_ __/
|
20
|
+
# |_____/ \___|_|\___|\__\___|
|
21
|
+
#
|
22
|
+
#
|
23
|
+
# About to delete files!
|
24
|
+
# To continue, press ENTER. To abort, press Ctrl+C...
|
25
|
+
module Klaxon
|
26
|
+
|
27
|
+
YESNO = :yesno
|
28
|
+
ENTER = :enter
|
29
|
+
RANDOM = :random
|
30
|
+
|
31
|
+
# Issues the alert prompt, unless running in a CI environment. The prompt is always
|
32
|
+
# to STDERR.
|
33
|
+
#
|
34
|
+
# When run with a block, denying the prompt will simply not call the block. When
|
35
|
+
# run without a block, denying will cause a system exit.
|
36
|
+
#
|
37
|
+
# * +:banner:+ - A large block banner displayed figlet-style
|
38
|
+
# * +:description:+ - Paragraph text for the prompt, with line feeds preserved
|
39
|
+
# * +:color:+ - A symbol like :red or :yellow which will color the whole prompt
|
40
|
+
# * +:type:+ - Either :enter (the default), :yesno, :random, or literal text
|
41
|
+
# * +:ci:+ - If nil, auto-detect a CI environment from the ENV; if true, behave like a CI environment; if false, halt if it is a CI environment
|
42
|
+
#
|
43
|
+
def self.alert(banner: nil, description: nil, color: nil, type: nil, ci: nil, &dangerous)
|
44
|
+
execute = proc do
|
45
|
+
if dangerous
|
46
|
+
return dangerous.call
|
47
|
+
else
|
48
|
+
return true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
halt = proc do
|
53
|
+
if dangerous
|
54
|
+
STDERR.puts "\nSkipping.".colorize color
|
55
|
+
return false
|
56
|
+
else
|
57
|
+
STDERR.puts "\nExiting."
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
prompt = proc do |msg,&ok|
|
63
|
+
STDERR.print msg
|
64
|
+
begin
|
65
|
+
if ok[STDIN.gets.chomp.downcase]
|
66
|
+
execute.call
|
67
|
+
end
|
68
|
+
rescue Interrupt
|
69
|
+
end
|
70
|
+
|
71
|
+
halt.call
|
72
|
+
end
|
73
|
+
|
74
|
+
if ci == true
|
75
|
+
execute.call
|
76
|
+
elsif !STDIN.isatty && (ENV['CI'] || ENV['JENKINS_URL'])
|
77
|
+
if ci != false
|
78
|
+
execute.call
|
79
|
+
else
|
80
|
+
halt.call
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if banner
|
85
|
+
STDERR.puts
|
86
|
+
STDERR.puts Artii::Base.new.asciify(banner).each_line.map {|line| " " + line[0..TermInfo.screen_width-4] }.join.colorize color
|
87
|
+
STDERR.puts
|
88
|
+
end
|
89
|
+
|
90
|
+
if description
|
91
|
+
STDERR.puts description.colorize color
|
92
|
+
end
|
93
|
+
|
94
|
+
case type
|
95
|
+
when ENTER, nil
|
96
|
+
prompt.call "To continue, press ENTER. To abort, press Ctrl+C..." do
|
97
|
+
true
|
98
|
+
end
|
99
|
+
when YESNO
|
100
|
+
prompt.call "Continue? [y/N]: " do |val|
|
101
|
+
['y', 'yes'].include?(val)
|
102
|
+
end
|
103
|
+
when RANDOM
|
104
|
+
digits = SecureRandom.hex(2)
|
105
|
+
prompt.call "To continue, type #{digits.upcase.split(//).join(" ")}\n> " do |val|
|
106
|
+
val.gsub(/\s+/, '') == digits
|
107
|
+
end
|
108
|
+
else
|
109
|
+
prompt.call "To continue, type \"#{type}\"\n> " do |val|
|
110
|
+
val == type
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: klaxon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Calhoun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: artii
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-terminfo
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Before a potentially dangerous or destructive action, issue a programmable
|
56
|
+
warning prompt.
|
57
|
+
email:
|
58
|
+
- ryanjamescalhoun@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/klaxon.rb
|
66
|
+
- lib/klaxon/version.rb
|
67
|
+
homepage: https://github.com/ryancalhoun/klaxon
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.0.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: An interactive warning prompt for the command-line
|
90
|
+
test_files: []
|