How to get ARGV options on Rails 6.1
Asked Answered
I

1

2

Some of my Rails tests require parameters from command line. After Rails 6.1. ARGV has been (for whatever reason) cleared and not available in application.

Is there an alternative way to get parameters send to rails command?

Interstratify answered 16/4, 2021 at 11:18 Comment(1)
Not worthy of a proper answer. But doing this is a possible hacky way of doing it: ps -o "pid,command" | grep #{Process.pid}. I.e. find the current process and look through the string output (includes the grep command too).Skilken
S
0

Depending on what you're doing, you might be able to use Rake.application.top_level_tasks. For rake tasks, this is set by rake itself. But it may also be set for your use-case too.

For my use-case, I was able to see if migrations were running, by doing:

if File.basename($0) == "rake" && Rake.application.top_level_tasks == ["db:migrate"]
  # DB Migration is runnning...
end

See: https://mcmap.net/q/176617/-how-do-i-detect-in-rails-if-i-am-running-a-rake-command

Skilken answered 30/5, 2022 at 6:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.