Skip to content

Commit

Permalink
Added confirmation for when a user invokes the start/stop/restart com…
Browse files Browse the repository at this point in the history
…mands.
  • Loading branch information
Michael van Rooijen committed Jan 31, 2010
1 parent bf856bf commit cf6fcd0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/webbynode/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ def api
def notify(msg)
Webbynode::Notify.message(msg)
end

def yes?(question)
answer = ask(question)
return true if answer == "y" or answer == "yes"
return false if answer == "n" or answer == "no"
exit
end

def no?(question)
answer = ask(question)
return true if answer == "n" or answer == "no"
return false if answer == "y" or answer == "yes"
exit
end

def validate_initialization
raise Webbynode::GitNotRepoError,
Expand Down
3 changes: 3 additions & 0 deletions lib/webbynode/commands/restart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Restart < Webbynode::Command
requires_initialization!

def execute
exit if no?("Are you sure you wish to restart your webby? (y/n)")

api.webbies.each do |webby|
if webby[1][:ip].eql?(git.parse_remote_ip)
if webby[1][:status].eql?("on")
Expand All @@ -18,5 +20,6 @@ def execute
end
end
end

end
end
2 changes: 2 additions & 0 deletions lib/webbynode/commands/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Start < Webbynode::Command
requires_initialization!

def execute
exit if no?("Are you sure you wish to start your webby? (y/n)")

api.webbies.each do |webby|
if webby[1][:ip].eql?(git.parse_remote_ip)
unless webby[1][:status].eql?("on")
Expand Down
2 changes: 2 additions & 0 deletions lib/webbynode/commands/stop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Stop < Webbynode::Command
requires_initialization!

def execute
exit if no?("Are you sure you wish to shutdown your webby? (y/n)")

api.webbies.each do |webby|
if webby[1][:ip].eql?(git.parse_remote_ip)
unless webby[1][:status].eql?("off")
Expand Down

0 comments on commit cf6fcd0

Please sign in to comment.