From 55addc74dcbb0206a6c7b4c949310f183afd6e6c Mon Sep 17 00:00:00 2001 From: Petrik Date: Thu, 9 Mar 2023 21:55:51 +0100 Subject: [PATCH] Use Thor for built-in secret task Currently we use both Thor and Rake for `bin/rails` commands. We eventually want to get all the built-ins task promoted to Thor Commands. This migrates the secret task to Thor. --- .../lib/rails/commands/secret/secret_command.rb | 13 +++++++++++++ railties/lib/rails/tasks/misc.rake | 6 ------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 railties/lib/rails/commands/secret/secret_command.rb diff --git a/railties/lib/rails/commands/secret/secret_command.rb b/railties/lib/rails/commands/secret/secret_command.rb new file mode 100644 index 0000000000000..5c29fef9293c1 --- /dev/null +++ b/railties/lib/rails/commands/secret/secret_command.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Rails + module Command + class SecretCommand < Base # :nodoc: + desc "secret", "Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)." + def perform + require "securerandom" + puts SecureRandom.hex(64) + end + end + end +end diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake index f22e3e1f26450..1c1a793070c49 100644 --- a/railties/lib/rails/tasks/misc.rake +++ b/railties/lib/rails/tasks/misc.rake @@ -1,11 +1,5 @@ # frozen_string_literal: true -desc "Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)." -task :secret do - require "securerandom" - puts SecureRandom.hex(64) -end - desc "List versions of all Rails frameworks and the environment" task about: :environment do puts Rails::Info