-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interactive prompting for missing parameters on create/update. (#161
- Loading branch information
Showing
11 changed files
with
137 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Moonshot | ||
# The AlwaysUseDefaultSource will always use the previous value in | ||
# the stack, or use the default value during stack creation. This is | ||
# useful if plugins provide the value for a parameter, and we don't | ||
# want to prompt the user for an override. Of course, overrides from | ||
# answer files or command-line arguments will always apply. | ||
class AlwaysUseDefaultSource | ||
def get(sp) | ||
unless sp.default? | ||
raise "Parameter #{sp.name} does not have a default, cannot use AlwaysUseDefaultSource!" | ||
end | ||
|
||
# Don't do anything, the default will apply on create, and the | ||
# previous value will be used on update. | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'colorize' | ||
|
||
module Moonshot | ||
class AskUserSource | ||
def get(sp) | ||
return unless Moonshot.config.interactive | ||
|
||
@sp = sp | ||
|
||
prompt | ||
loop do | ||
input = gets.chomp | ||
|
||
if String(input).empty? && @sp.default? | ||
# We will use the default value, print it here so the output is clear. | ||
puts 'Using default value.' | ||
return | ||
elsif String(input).empty? | ||
puts "Cannot proceed without value for #{@sp.name}!" | ||
else | ||
@sp.set(String(input)) | ||
return | ||
end | ||
|
||
prompt | ||
end | ||
end | ||
|
||
private | ||
|
||
def prompt | ||
print "(#{@sp.name})".light_black | ||
print " #{@sp.description}" unless @sp.description.empty? | ||
print " [#{@sp.default}]".light_black if @sp.default? | ||
print ': ' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters