ruby-nginx 1.0.0.pre.beta.2 → 1.0.0.pre.beta.3
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/ruby/nginx/commands/helpers/prompt_helper.rb +73 -0
- data/lib/ruby/nginx/commands/helpers/sudo_helper.rb +32 -0
- data/lib/ruby/nginx/commands/install_mkcert.rb +2 -0
- data/lib/ruby/nginx/commands/install_nginx.rb +4 -2
- data/lib/ruby/nginx/commands/terminal_command.rb +7 -23
- data/lib/ruby/nginx/version.rb +1 -1
- metadata +3 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23ed81e982f332b222ea6f29a2e223ad1e114e5fb57953277defad3a164ca383
|
4
|
+
data.tar.gz: b68c5854801f99463f05401990c434d6dbe8de74f401c03a6b2edd5a6fb13019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7446042ae6a1a49eb49f034a455497d3a7eb4032800e124520db8ba74ef0a937a394de8b24cd58bb7cc12340b1d569574e5ef4e9fae0d25eeb3131d499979833
|
7
|
+
data.tar.gz: d3b9bc26b024f25b1925f7f18a51bd0a13f0753434458b6fc6ce4d9c59cfed661b534522b84851220bc16327f5654ad7dd00d85878b5dd3c3088ed2c21a452a1
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruby
|
4
|
+
module Nginx
|
5
|
+
module Commands
|
6
|
+
module Helpers
|
7
|
+
module PromptHelper
|
8
|
+
def yes?(question)
|
9
|
+
return true if ENV["SKIP_PROMPT"]
|
10
|
+
|
11
|
+
retry_question = false
|
12
|
+
|
13
|
+
loop do
|
14
|
+
response = ask_question(question)
|
15
|
+
|
16
|
+
if !response.nil?
|
17
|
+
reset_line if retry_question
|
18
|
+
return print_confirm(question, response)
|
19
|
+
end
|
20
|
+
|
21
|
+
print_invalid_input && previous_line && reset_line
|
22
|
+
retry_question = true
|
23
|
+
end
|
24
|
+
rescue Interrupt
|
25
|
+
next_line && print_confirm(question, false)
|
26
|
+
raise Ruby::Nginx::AbortError, "Operation aborted"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def ask_question(question)
|
32
|
+
print "[Ruby::Nginx] #{question} \e[90m(Y/n)\e[0m "
|
33
|
+
|
34
|
+
case $stdin.gets.chomp.downcase
|
35
|
+
when "y", "yes"
|
36
|
+
true
|
37
|
+
when "n", "no"
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_confirm(question, allowed)
|
43
|
+
previous_line && reset_line
|
44
|
+
|
45
|
+
print "[Ruby::Nginx] #{question} \e[32m#{allowed ? "yes" : "no"}\e[0m\n"
|
46
|
+
allowed
|
47
|
+
end
|
48
|
+
|
49
|
+
def reset_line
|
50
|
+
# 2K = clear line, 1G = move to first column
|
51
|
+
print "\e[2K\e[1G"
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
def previous_line
|
56
|
+
print "\e[1A"
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
def next_line
|
61
|
+
print "\n"
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_invalid_input
|
66
|
+
print "\e[31m>>\e[0m Invalid input."
|
67
|
+
true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tty/command"
|
4
|
+
require_relative "prompt_helper"
|
5
|
+
|
6
|
+
module Ruby
|
7
|
+
module Nginx
|
8
|
+
module Commands
|
9
|
+
module Helpers
|
10
|
+
module SudoHelper
|
11
|
+
include Ruby::Nginx::Commands::Helpers::PromptHelper
|
12
|
+
|
13
|
+
def sudoify(cmd, sudo, reason)
|
14
|
+
return cmd unless sudo
|
15
|
+
|
16
|
+
if sudo_access? || yes?(reason)
|
17
|
+
"sudo #{cmd}"
|
18
|
+
else
|
19
|
+
raise Ruby::Nginx::AbortError, "Operation aborted"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def sudo_access?
|
26
|
+
TerminalCommand.new(cmd: "sudo -n true").run.success?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -14,10 +14,12 @@ module Ruby
|
|
14
14
|
def run
|
15
15
|
return if installed?
|
16
16
|
|
17
|
-
|
17
|
+
puts "\e[0;33m#{cmd}\e[0m"
|
18
|
+
|
19
|
+
if yes?("Would you like to install NGINX?")
|
18
20
|
super
|
19
21
|
else
|
20
|
-
raise Ruby::Nginx::AbortError, "
|
22
|
+
raise Ruby::Nginx::AbortError, "NGINX is required to continue. Please install NGINX."
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -1,12 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "tty/command"
|
4
|
-
|
4
|
+
require_relative "helpers/prompt_helper"
|
5
|
+
require_relative "helpers/sudo_helper"
|
5
6
|
|
6
7
|
module Ruby
|
7
8
|
module Nginx
|
8
9
|
module Commands
|
9
10
|
class TerminalCommand
|
11
|
+
include Ruby::Nginx::Commands::Helpers::PromptHelper
|
12
|
+
include Ruby::Nginx::Commands::Helpers::SudoHelper
|
13
|
+
|
10
14
|
attr_reader :cmd, :user, :error_type, :printer, :result
|
11
15
|
|
12
16
|
def initialize(cmd:, user: nil, raise: nil, printer: :null)
|
@@ -22,28 +26,8 @@ module Ruby
|
|
22
26
|
raise @error_type, @result.err if error_type && @result.failure?
|
23
27
|
|
24
28
|
@result
|
25
|
-
|
26
|
-
|
27
|
-
protected
|
28
|
-
|
29
|
-
def yes?(question)
|
30
|
-
ENV["SKIP_PROMPT"] || TTY::Prompt.new.yes?("[Ruby::Nginx] #{question}")
|
31
|
-
end
|
32
|
-
|
33
|
-
def sudoify(cmd, sudo, reason)
|
34
|
-
return cmd unless sudo
|
35
|
-
|
36
|
-
if sudo_access? || yes?(reason)
|
37
|
-
"sudo #{cmd}"
|
38
|
-
else
|
39
|
-
raise Ruby::Nginx::AbortError, "Operation aborted"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def sudo_access?
|
46
|
-
TerminalCommand.new(cmd: "sudo -n true").run.success?
|
29
|
+
rescue Interrupt
|
30
|
+
raise Ruby::Nginx::AbortError, "Operation aborted"
|
47
31
|
end
|
48
32
|
end
|
49
33
|
end
|
data/lib/ruby/nginx/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nginx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bert McCutchen
|
@@ -58,20 +58,6 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 0.10.1
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: tty-prompt
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: 0.3.0
|
68
|
-
type: :runtime
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 0.3.0
|
75
61
|
description: Utility gem with an added CLI for configuring NGINX with SSL.
|
76
62
|
email:
|
77
63
|
- mail@bertm.dev
|
@@ -89,6 +75,8 @@ files:
|
|
89
75
|
- lib/ruby/nginx/commands/add_host_mapping.rb
|
90
76
|
- lib/ruby/nginx/commands/add_nginx_config.rb
|
91
77
|
- lib/ruby/nginx/commands/create_mkcert_certificate.rb
|
78
|
+
- lib/ruby/nginx/commands/helpers/prompt_helper.rb
|
79
|
+
- lib/ruby/nginx/commands/helpers/sudo_helper.rb
|
92
80
|
- lib/ruby/nginx/commands/install_mkcert.rb
|
93
81
|
- lib/ruby/nginx/commands/install_nginx.rb
|
94
82
|
- lib/ruby/nginx/commands/nginx_options.rb
|