diff --git a/lib/gitlab/cli.rb b/lib/gitlab/cli.rb index 4c8b80722..c94e15552 100644 --- a/lib/gitlab/cli.rb +++ b/lib/gitlab/cli.rb @@ -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 diff --git a/lib/gitlab/cli_helpers.rb b/lib/gitlab/cli_helpers.rb index 249d9d1fc..73b628efb 100644 --- a/lib/gitlab/cli_helpers.rb +++ b/lib/gitlab/cli_helpers.rb @@ -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]