Skip to content

Commit

Permalink
add confirmation for destructive commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ committed May 20, 2014
1 parent 01fe039 commit af92ff5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/gitlab/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def self.run(cmd, args=[])
command_args = args[0..-2]
end

confirm_command(cmd)

begin
data = args.any? ? Gitlab.send(cmd, *command_args) : Gitlab.send(cmd)
rescue => e
Expand Down
15 changes: 15 additions & 0 deletions lib/gitlab/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ def excluded_fields(args)
end
end

# Confirms command with a desctructive action.
#
# @return [String]
def confirm_command(cmd)
if cmd.start_with?('remove_') || cmd.start_with?('delete_')
puts "Are you sure? (y/n)"
if %w(y yes).include?($stdin.gets.to_s.strip.downcase)
puts 'Proceeding..'
else
puts 'Command aborted.'
exit(1)
end
end
end

# Table with available commands.
#
# @return [String]
Expand Down

0 comments on commit af92ff5

Please sign in to comment.