firespring_dev_commands 2.1.13.pre.alpha.2 → 2.1.13.pre.alpha.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/firespring_dev_commands/common.rb +82 -7
- data/lib/firespring_dev_commands/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f84e05f66ceae5becece425cea392a8f1e0bb7e4f6c7f8ef6d6c7bfe068405e
|
4
|
+
data.tar.gz: 3367ff552bdea261d9612f1a92e10a1f69031e932173ff6e3ae783fa386de968
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bea1ed2293666af0990773ad2a38c9c5fe38d37a17773ab8c256a4bf08560f90d7fe7c1c4ecf3048fb3c3e08e9596a352ab9541ad2f587bb573bfdee97315b9
|
7
|
+
data.tar.gz: 3a91544429995e944f13fb12e66e969725614d076a23ee50cac2dacab475b04fe6fc0bffd1ae970773b95db2e79c1b800a9ba0892b774c3ec79ac13943c153e2
|
@@ -40,7 +40,8 @@ module Dev
|
|
40
40
|
# Wraps a block of code in a y/n question.
|
41
41
|
# If the user answers 'y' then the block is executed.
|
42
42
|
# If the user answers 'n' then the block is skipped.
|
43
|
-
|
43
|
+
# @deprecated Please use {Common#when_confirmed} instead
|
44
|
+
def with_confirmation(message, default = 'y', color_message: true)
|
44
45
|
message = "\n #{message}" << '? '.light_green
|
45
46
|
message = message.light_green if color_message
|
46
47
|
print message
|
@@ -49,15 +50,89 @@ module Dev
|
|
49
50
|
answer = default
|
50
51
|
answer = $stdin.gets unless ENV['NON_INTERACTIVE'] == 'true'
|
51
52
|
|
52
|
-
|
53
|
-
puts
|
54
|
-
yield
|
55
|
-
elsif exit_unconfirmed
|
53
|
+
unless answer.strip.casecmp('y').zero?
|
56
54
|
puts "\n Cancelled.\n".light_yellow
|
57
55
|
exit 1
|
58
|
-
else
|
59
|
-
puts
|
60
56
|
end
|
57
|
+
puts
|
58
|
+
|
59
|
+
yield
|
60
|
+
end
|
61
|
+
|
62
|
+
# Exits unless the user confirms they want to continue
|
63
|
+
# If the user answers 'y' then the code will continue
|
64
|
+
# All other inputs cause the code to exit
|
65
|
+
def exit_unless_confirmed(message, default: nil, colorize: true)
|
66
|
+
# If a default is given, it must be y or n
|
67
|
+
raise 'invalid default' if default && !%w(y n).include?(default)
|
68
|
+
|
69
|
+
# print the colorized message (if requested) with the default (if given)
|
70
|
+
print(confirmation_message(message, default:, colorize:))
|
71
|
+
|
72
|
+
# Default to the default
|
73
|
+
# Read from stdin unless non_interactive is set to true
|
74
|
+
answer = gather_input(default:)
|
75
|
+
|
76
|
+
return if answer.casecmp('y').zero?
|
77
|
+
|
78
|
+
puts "\n Cancelled.\n".light_yellow
|
79
|
+
exit 1
|
80
|
+
end
|
81
|
+
|
82
|
+
# Wraps a block of code in a y/n question
|
83
|
+
# If the user answers 'y' then the block is executed
|
84
|
+
# All other inputs cause the block to be skipped
|
85
|
+
def when_confirmed(message, default: nil, colorize: true)
|
86
|
+
# If a default is given, it must be y or n
|
87
|
+
raise 'invalid default' if default && !%w(y n).include?(default)
|
88
|
+
|
89
|
+
# print the colorized message (if requested) with the default (if given)
|
90
|
+
print(confirmation_message(message, default:, colorize:))
|
91
|
+
|
92
|
+
# Default to the default
|
93
|
+
# Read from stdin unless non_interactive is set to true
|
94
|
+
answer = gather_input(default:)
|
95
|
+
|
96
|
+
# Yield to the block if confirmed
|
97
|
+
yield if answer.casecmp('y').zero?
|
98
|
+
end
|
99
|
+
|
100
|
+
# Receive a string from the user on stdin unless non_interactive is set to true
|
101
|
+
# If a default value was specified and no answer was given, return the default
|
102
|
+
def gather_input(default: nil)
|
103
|
+
answer = $stdin.gets.to_s.strip unless ENV['NON_INTERACTIVE'] == 'true'
|
104
|
+
answer.to_s.strip
|
105
|
+
return default if default && answer.empty?
|
106
|
+
|
107
|
+
answer
|
108
|
+
end
|
109
|
+
|
110
|
+
# Build a confirmation message, colorizing each individual part appropriately
|
111
|
+
# Include the default value in the message if one was specified
|
112
|
+
def confirmation_message(question, default:, colorize:)
|
113
|
+
message = conditional_colorize(question, colorize:, color: :light_green)
|
114
|
+
options = conditional_colorize('(', colorize:, color: :light_green)
|
115
|
+
options << conditional_colorize('y', colorize:, color: :light_yellow)
|
116
|
+
options << conditional_colorize('/', colorize:, color: :light_green)
|
117
|
+
options << conditional_colorize('n', colorize:, color: :light_yellow)
|
118
|
+
options << conditional_colorize(')', colorize:, color: :light_green)
|
119
|
+
|
120
|
+
unless default.to_s.strip.empty?
|
121
|
+
options << ' '
|
122
|
+
options << conditional_colorize('[', colorize:, color: :light_green)
|
123
|
+
options << conditional_colorize(default.to_s.strip, colorize:, color: :light_yellow)
|
124
|
+
options << conditional_colorize(']', colorize:, color: :light_green)
|
125
|
+
end
|
126
|
+
|
127
|
+
options << conditional_colorize(':', colorize:, color: :light_green)
|
128
|
+
"#{message} #{options} "
|
129
|
+
end
|
130
|
+
|
131
|
+
# Colorize the string if it has been requested
|
132
|
+
def conditional_colorize(string, colorize:, color:)
|
133
|
+
return string.send(color) if colorize
|
134
|
+
|
135
|
+
string
|
61
136
|
end
|
62
137
|
|
63
138
|
# Asks for user input using the given message and returns it
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firespring_dev_commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.13.pre.alpha.
|
4
|
+
version: 2.1.13.pre.alpha.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Firespring
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|